admost_flutter_plugin

A new Flutter plugin that uses native platform views to show AdMost mediation platform banner ads!

This plugin also has support for Interstitial and Reward ads.

Installation

Add thidars to your pubspec.yml dependencies:

admost_flutter_plugin: "^1.3.2"

Add the related dependencies into android/app/build.graddle. Dependencies changes according to your ad network choices. The items shown below represents Meta audience network and Admob dependencies chosen as sample. Refer to the admost android documentation for necessary dependencies for selected ad networks for an application.

    dependencies {
        implementation 'com.admost.sdk:facebook-adapter:6.17.0.a47'
        implementation 'androidx.annotation:annotation:1.2.0'
        
        implementation 'com.google.android.gms:play-services-ads:23.2.0' 
        implementation 'com.admost.sdk:admob-adapter:23.0.0.a47'
    }

It may be needed to add extra repository based on ad network selection. This configuration can be found in the admost android documentation as well.

Simple Example

import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:admost_flutter_plugin/admost.dart';
import 'package:admost_flutter_plugin/admost_interstitial.dart';
import 'package:admost_flutter_plugin/admost_rewarded.dart';
import 'package:admost_flutter_plugin/admost_ad_events.dart';
import 'package:admost_flutter_plugin/admost_banner.dart';
import 'package:admost_flutter_plugin/admost_banner_size.dart';
import 'package:admost_flutter_plugin/admost_native_ad.dart';
import 'package:admost_flutter_plugin/admost_remote_config.dart';
import 'dart:io';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  initAdmost();
  runApp(MyApp());
}

Future<void> initAdmost() async {
  //Admost.setCustomVendors({"ADMOST": true, "APPLOVIN": false});
  //Admost.setCanRequestAds(true);
  bool initStatus = await Admost.initialize(
        appId: Platform.isIOS
            ? "15066ddc-9c18-492c-8185-bea7e4c7f88c"
            : "6cc8e89a-b52a-4e9a-bb8c-579f7ec538fe",
        userConsent: "1",
        subjectToGDPR: "1",
        subjectToCCPA: "0");

    print("<ADMOST> init status: ${initStatus}");
    
    remoteConfig();
  //Admost.setUserId("myUniqueUserId");
  //AdmostATTrackingManager.requestTrackingAuthorization().then((value) => print("TrackingAuthorizationStatus: ${value}"));
  //AdmostATTrackingManager.getTrackingAuthorizationStatus().then((value) => print("TrackingAuthorizationStatus: ${value}"));
}

void remoteConfig() async {
  bool? response =
      await AdMostRemoteConfig.getBoolean(key: "isDebug", defaultValue: true);
  String? response2 = await AdMostRemoteConfig.getString(
      key: "version", defaultValue: "no value");
  num? response4 =
      await AdMostRemoteConfig.getNum(key: "doubleValue", defaultValue: 1.0);

  print(
      "<ADMOST> RemoteConfigTest isDebug ${response} / ${response2} / ${response4}");
}

/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: MyHomePage(),
      ),
    );
  }
}

/// This is the stateless widget that the main application instantiates.
class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String interstitialText = 'Load Interstitial';
  String rewardedText = 'Load Rewarded';

  AdmostInterstitial? interstitialAd;
  AdmostRewarded? rewardAd;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(10),
      child: Center(
        widthFactor: 2,
        heightFactor: 2,
        child: Column(children: <Widget>[
          Card(
            child: InkWell(
              onTap: () {
                Admost.startTestSuite(Platform.isIOS
                    ? "15066ddc-9c18-492c-8185-bea7e4c7f88c"
                    : "6cc8e89a-b52a-4e9a-bb8c-579f7ec538fe");
              },
              child: Center(
                widthFactor: 2,
                heightFactor: 2,
                child: Text("Start Tester Info"),
              ),
            ),
          ),
          Card(
            child: InkWell(
              splashColor: Colors.blue.withAlpha(30),
              onTap: () async {
                if (interstitialAd == null) {
                  interstitialAd = AdmostInterstitial(
                    zoneId: Platform.isIOS
                        ? '39f74377-5682-436a-9338-9d1c4df410bd'
                        : 'f99e409b-f9ab-4a2e-aa9a-4d143e6809ae',
                    listener: (AdmostAdEvent event, Map<String, dynamic> args) {
                      if (event == AdmostAdEvent.loaded) {
                        print("<ADMOST> Interstitial loaded");
                        print(
                            "<ADMOST> Interstitial network: ${args['network']}");
                        print("<ADMOST> Interstitial ecpm: ${args['ecpm']}");
                        interstitialText = 'Show Interstitial';
                        setState(() {
                          interstitialText;
                        });
                      }
                      if (event == AdmostAdEvent.dismissed) {
                        print("<ADMOST> Interstitial dismissed");
                        interstitialText = 'Load Interstitial';
                        setState(() {
                          interstitialText;
                        });
                      }
                      if (event == AdmostAdEvent.opened) {
                        print("<ADMOST> Interstitial Opened");
                      }
                      if (event == AdmostAdEvent.failedToLoad) {
                        print("<ADMOST> Interstitial failedToLoad");
                        print(
                            "<ADMOST> Interstitial Error code: ${args['errorCode']}");
                        print(
                            "<ADMOST> Interstitial Error description: ${args['errorMessage']}");
                      }
                      if (event == AdmostAdEvent.failedToShow) {
                        print("<ADMOST> Interstitial failedToShow");
                        print(
                            "<ADMOST> Interstitial Error code: ${args['errorCode']}");
                        print(
                            "<ADMOST> Interstitial Error description: ${args['errorMessage']}");
                      }
                    },
                  );
                }

                if (await interstitialAd!.isLoaded ?? false) {
                  interstitialAd!.show();
                  // If you want to add tag, you should remove the line above and use the code below (optional)
                  // interstitialAd.show("YOUR TAG");
                } else {
                  interstitialAd!.load();
                }
              },
              child: Center(
                widthFactor: 2,
                heightFactor: 2,
                child: Text(interstitialText),
              ),
            ),
          ),
          Card(
            child: InkWell(
              splashColor: Colors.blue.withAlpha(30),
              onTap: () async {
                if (rewardAd == null) {
                  rewardAd = AdmostRewarded(
                    zoneId: Platform.isIOS
                        ? '2bdefd44-5269-4cbc-b93a-373b74a2f067'
                        : '88cfcfd0-2f8c-4aba-9f36-cc0ac99ab140',
                    listener: (AdmostAdEvent event, Map<String, dynamic> args) {
                      if (event == AdmostAdEvent.loaded) {
                        print("<ADMOST> Rewarded loaded");

                        print("<ADMOST> Rewarded network: ${args['network']}");
                        print("<ADMOST> Rewarded ecpm: ${args['ecpm']}");
                        rewardedText = 'Show Rewarded';
                        setState(() {
                          rewardedText;
                        });
                      } else if (event == AdmostAdEvent.dismissed) {
                        print("<ADMOST> Rewarded dismissed");
                        rewardedText = 'Load Rewarded';
                        setState(() {
                          rewardedText;
                        });
                      } else if (event == AdmostAdEvent.failedToLoad) {
                        print("<ADMOST> Rewarded failedToLoad");
                        print(
                            "<ADMOST> Rewarded Error code: ${args['errorCode']}");
                        print(
                            "<ADMOST> Rewarded Error description: ${args['errorMessage']}");
                      } else if (event == AdmostAdEvent.failedToShow) {
                        print("<ADMOST>  Rewarded failedToShow");
                        print(
                            "<ADMOST> Rewarded Error code: ${args['errorCode']}");
                        print(
                            "<ADMOST> Rewarded Error description: ${args['errorMessage']}");
                      } else if (event == AdmostAdEvent.opened) {
                        print("<ADMOST> Rewarded Opened");
                      } else if (event == AdmostAdEvent.completed) {
                        print("<ADMOST> Rewarded completed");
                      }
                    },
                  );
                }

                if (await rewardAd!.isLoaded ?? false) {
                  rewardAd!.show();
                  // If you want to add tag, you should remove the line above and use the code below (optional)
                  // rewardAd.show("YOUR TAG");
                } else {
                  rewardAd!.load();
                }
              },
              child: Center(
                widthFactor: 2,
                heightFactor: 2,
                child: Text(rewardedText),
              ),
            ),
          ),
          Card(
            child: AdmostBanner(
              adUnitId: Platform.isIOS
                  ? "b4009772-de04-42c4-bbaa-c18da9e4a1ab"
                  : '9fb970db-7d96-4ef2-ac8c-d88ec22270ff',
              adSize: AdmostBannerSize.BANNER,
              listener: (AdmostAdEvent event, Map<String, dynamic> args) {
                if (event == AdmostAdEvent.loaded) {
                  print("<ADMOST> Banner Ad network: ${args['network']}");
                  print("<ADMOST> Banner Ad ecpm: ${args['ecpm']}");
                  print("<ADMOST> Banner Ad Loaded");
                }
                if (event == AdmostAdEvent.clicked) {
                  print("<ADMOST> Banner Ad network: ${args['network']}");
                  print("<ADMOST> Banner Ad clicked");
                }
                if (event == AdmostAdEvent.failedToLoad) {
                  print(
                      "<ADMOST> Banner Error description: ${args['errorMessage']}");
                  print("<ADMOST Banner Error code: ${args['errorCode']}");
                }
              },
              //optional
              //tag:"YOUR TAG",
            ),
          ),
          Card(
            child: AdmostNativeAd(
              adUnitId: Platform.isIOS
                  ? 'c72a4a52-23c5-4c34-9eb1-7bbc4c08c7e4'
                  : '951d398e-b6ec-40a7-bc80-6b4b223418df',
              adSize: AdmostBannerSize.MEDIUM_RECTANGLE,
              xibNameForIOS: 'AMRNativeAdBaseView250',
              listener: (AdmostAdEvent event, Map<String, dynamic> args) {
                if (event == AdmostAdEvent.loaded) {
                  print("<ADMOST> Native Ad network: ${args['network']}");
                  print("<ADMOST> Native Ad ecpm: ${args['ecpm']}");
                  print("<ADMOST> Native Ad Loaded");
                }
                if (event == AdmostAdEvent.clicked) {
                  print("<ADMOST> Native Ad network: ${args['network']}");
                  print("<ADMOST> Native Ad clicked");
                }
                if (event == AdmostAdEvent.failedToLoad) {
                  print("<ADMOST> Native Ad Error code: ${args['errorCode']}");
                  print(
                      "<ADMOST> Native Ad Error description: ${args['errorMessage']}");
                }
              },
              //optional
              //tag:"YOUR TAG",
            ),
          )
        ]),
      ),
    );
  }
}



Custom Native Ads

IOS

For IOS it is enough to add the following parameter to the AdmostNativeAd view;

xibNameForIOS: 'AMRNativeAdBaseView250',

Android

As in the MainActivity in the example project, you can follow the following steps;

  1. Define a layout file in the android layout folder for your custom native design
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="120dp"
             android:background="@android:color/white"
             android:orientation="horizontal">

    <ImageView
        android:id="@+id/admost_flutter_back_image"
        android:layout_width="145dp"
        android:layout_marginLeft="5dp"
        android:adjustViewBounds="true"
        android:layout_gravity="left|center"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:visibility="gone"/>

    <ImageView
        android:id="@+id/admost_flutter_main_image"
        android:layout_width="145dp"
        android:layout_marginLeft="5dp"
        android:adjustViewBounds="true"
        android:layout_gravity="left|center"
        android:layout_height="wrap_content"
        android:scaleType="fitXY" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="0dp">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|left"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/admost_flutter_icon"
                android:layout_width="14dp"
                android:layout_height="14dp"
                android:layout_marginRight="4dp"
                android:layout_marginTop="6dp"
                android:background="@null"
                android:scaleType="fitXY" />

            <TextView
                android:id="@+id/admost_flutter_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:layout_marginRight="15dp"
                android:maxLines="1"
                android:layout_marginTop="5dp"
                android:gravity="center_vertical"
                android:text="Title"
                android:textColor="#ff000000"
                android:textSize="14sp" />
        </LinearLayout>

        <TextView
            android:id="@+id/admost_flutter_attribution"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|right"
            android:layout_marginTop="30dp"
            android:layout_marginLeft="10dp"
            android:text="Ad"
            android:textColor="#ffacabab"
            android:textSize="12sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="35dp"
            android:layout_marginLeft="10dp"
            android:orientation="vertical">

            <TextView
                android:id="@+id/admost_flutter_detail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="5dp"
                android:ellipsize="end"
                android:lineSpacingExtra="3dp"
                android:maxLines="2"
                android:paddingBottom="5dp"
                android:paddingTop="8dp"
                android:text="Title Lorem ipsom dolor sit amet consaposod elit"
                android:textColor="#cc2a2e32"
                android:textSize="12sp"/>

            <Button
                android:id="@+id/admost_flutter_cta"
                android:layout_width="match_parent"
                android:layout_height="36dp"
                android:layout_marginBottom="12dp"
                android:layout_marginTop="-10dp"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="Go"
                android:textStyle="bold"
                android:textSize="14sp"
                android:textColor="@android:color/black"/>

        </LinearLayout>

        <LinearLayout
            android:id="@+id/admost_flutter_ad_choices"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:gravity="right"
            android:orientation="vertical"/>
    </RelativeLayout>

</LinearLayout>

  1. Create a AdMostViewBinder object in the MainActivity and assign this object as the static native binder
val binder: AdMostViewBinder = admost.sdk.AdMostViewBinder.Builder(R.layout.custom_layout_flutter)
                .iconImageId(R.id.cardIcon)
                .titleId(R.id.cardTitle)
                .callToActionId(R.id.CallToActionTextView)
                .textId(R.id.cardDetailText)
                .attributionId(R.id.cardAttribution)
                .mainImageId(R.id.cardImage)
                .backImageId(R.id.cardBack)
                .privacyIconId(R.id.ad_choices)
                .isRoundedMode(true)
                .build()

AdmostFLTNativeAdBinder.getInstance().binder = binder;

Track IAP

IOS

Admost.trackIAPForIOS(transactionId, currency, amount, ['tag1', 'tag2']);

Android

Admost.trackIAPForAndroid(originalJSON, signature, currency, amount, ['tag1', 'tag2'])

UMP (CMP) Support

Starting January 16, 2024 Publishers and developers using Google AdSense, Ad Manager, or AdMob will be required to use a Consent Management Platform (CMP) that has been certified by Google and has integrated with the IAB's Transparency and Consent Framework (TCF) when serving ads to users in the European Economic Area or the UK.

As Admost, we have integration with Google’s CMP tool User Messaging Platform (UMP). As a publisher, if you chose to continue with the UMP, you have to be sure about the following steps;

Add UMP SDK into your app and complete the integration according to the UMP integration documentation. Create a proper GDPR message for your app on the UMP dashboard. Select all active ad networks and "Admost" as Vendor on the UMP dashboard. Check Auto UMP Detection checkbox on Admost dashboard application edit popup. Inform Admost SDK about the result of the Consent flow with the following lines

Admost.setCanRequestAds(RESULT_OF_UMP_CANREQUESTADS);

If you are using CMP tool other than UMP, after completing the integration with the CMP tool you have to inform Admost SDK about the consent result of Custom Vendors including ADMOST before Admost initialization. Custom vendors can be any ad network used for monetization which are created manually and are not registered with IAB. Even if you don't have any extra custom vendors in your application, you have to add ADMOST as a custom vendor. You can use the following code snippet;

Admost.setCustomVendors({"ADMOST": VENDOR_CONSENT_BOOL, "APPLOVIN": VENDOR_CONSENT_BOOL});