3.2.1 • Published 23 days ago

@charmy.tech/react-native-admost v3.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
23 days ago

react-native-admost

Getting started

$ npm install @charmy.tech/react-native-admost --save

Android

  • You should follow the "Edit Files" section on AdMost
  • These dependencies already exist in gradle
  implementation 'com.admost.sdk:amr:+' 
  implementation 'com.google.android.gms:play-services-base:17.1.0' 

Update Project build.grandle

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://mvn-repo.admost.com/artifactory/amr-2' }
    }
}

IOS

  • You should follow the "Create your podfile and install" section on AdMost
  • These dependencies already exist in pod
  s.dependency "AMRSDK", "~> 1.5"

Usage

AdMostAdView

import React, { useEffect } from "react";
import { View, StatusBar, SafeAreaView } from "react-native";

import AdMost, { AdMostAdView } from "@charmy.tech/react-native-admost";

export default function App() {
  useEffect(() => {
    const appId = "<your-app-id>";

    AdMost.initAdMost({
      appId: appId,
      userConsent: true,
      subjectToGDPR: false,
      subjectToCCPA: false,
      userChild: false,
    });

    AdMost.setUserId("123123");
    AdMost.setCanRequestAds(false);
  }, []);

  return (
    <SafeAreaView style={{ flex: 1 }}>
      <View style={{ flex: 1, justifyContent: "center" }}>
        <StatusBar barStyle="dark-content" backgroundColor="#ffffff" />
        <AdMostAdView
          zoneId="c4a15983-d6fe-49ec-8e8b-844663190559"
          tag="Ragib"
          style={{ width: "100%", height: 50 }}
          onReady={({ nativeEvent }) => {
            console.log("ON_READY", nativeEvent);
          }}
          onFail={({ nativeEvent }) => {
            console.log("ON_FAIL", nativeEvent);
          }}
          onClick={({ nativeEvent }) => {
            console.log("ON_CLICK", nativeEvent);
          }}
        />

        <AdMostAdView
          zoneId="<admost-zone-id>"
          style={{ width: "100%", height: 250 }}
          onReady={({ nativeEvent }) => {
            console.log("ON_READY", nativeEvent);
          }}
          onFail={({ nativeEvent }) => {
            console.log("ON_FAIL", nativeEvent);
          }}
          onClick={({ nativeEvent }) => {
            console.log("ON_CLICK", nativeEvent);
          }}
        />
      </View>
    </SafeAreaView>
  );
}

Android Custom Layout

IOS Custom Layout

  • cp -r CustomXibs ${project_rootdir}/node_modules/@charmy.tech/react-native-admost/
  • pod install in ios folder
  • It should be like this
  • Set layoutName prop to view

Props

PropRequiredTypeDefault valueDescription
zoneIdtruestringAdMost zoneId
layoutNamefalsestringDEFAULTCustom layout name(layout_admost_native_250, CustomNative200x200)
tagfalsestringTags will let you monitor the performance of the ads across different dimensions for the same zone
styletrueViewStyleView style ({ width: "100%", height: 50 })
autoLoadDelayMsfalsenumber100Auto load delay (min 100 ms)
onReadyfalsefuncon ready callback event
onFailfalsefuncon fail callback event
onClickfalsefuncon click callback event

AdMostInterstitial

import React, { useEffect } from "react";
import { View, StatusBar, Button, SafeAreaView } from "react-native";

import AdMost, { AdMostInterstitial } from "@charmy.tech/react-native-admost";

export default function App() {
  useEffect(() => {
    const appId = "<your-app-id>";

    AdMost.initAdMost({
      appId: appId,
      userConsent: true,
      subjectToGDPR: false,
      subjectToCCPA: false,
      userChild: false,
    });
  }, []);

  // Interstitial events
  useEffect(() => {
    const adMostOnReadyEvent = AdMost.addInterstitialListener.onReady((e) => {
      console.log("ON_READY", e);
      AdMostInterstitial.showAd(e.zoneId, "TEST");
    });

    const adMostOnFailEvent = AdMost.addInterstitialListener.onFail((e) => {
      console.log("ON_FAIL", e);
    });

    const adMostOnDismissEvent = AdMost.addInterstitialListener.onDismiss((e) => {
      console.log("ON_DISMISS", e);
    });

    const adMostOnShownEvent = AdMost.addInterstitialListener.onShown((e) => {
      console.log("ON_SHOWN", e);
    });

    const adMostOnClickedEvent = AdMost.addInterstitialListener.onClicked((e) => {
      console.log("ON_CLICKED", e);
    });

    const adMostOnStatusChangedEvent = AdMost.addInterstitialListener.onStatusChanged((e) => {
      console.log("ON_STATUS_CHANGED", e);
    });

    return () => {
      adMostOnReadyEvent.remove();
      adMostOnFailEvent.remove();
      adMostOnDismissEvent.remove();
      adMostOnShownEvent.remove();
      adMostOnClickedEvent.remove();
      adMostOnStatusChangedEvent.remove();
    };
  });

  return (
    <SafeAreaView style={{ flex: 1 }}>
      <View style={{ flex: 1, justifyContent: "center" }}>
        <StatusBar barStyle="dark-content" backgroundColor="#ffffff" />
        <Button
          onPress={() => AdMostInterstitial.loadAd("<admost-zone-id>")}
          title="Load Interstitial Ad"
          color="red"
        />
      </View>
    </SafeAreaView>
  );
}

Methods

NameParamsReturnDescription
loadAd(zoneId: string)voidLoad ad
destroyAd(zoneId: string)voidDestroy Ad
showAd(zoneId: string, tag: string)PromiseShow when ad is ready
isLoading(zoneId: string)PromiseAd is loading
isLoaded(zoneId: string)PromiseAd is loaded

Events

NameParams
ON_READY{ network: string; ecpm: number; zoneId: string }
ON_FAIL{ errorCode: number; errorDescription?: string(iOS); zoneId: string }
ON_DISMISS{ message?: string(Android); zoneId: string }
ON_SHOWN{ network: string; zoneId: string }
ON_CLICKED{ network: string; zoneId: string }
ON_STATUS_CHANGED{ network: string; zoneId: string }

AdMostRewarded

import React, { useEffect } from "react";
import { View, StatusBar, Button, SafeAreaView } from "react-native";

import AdMost, { AdMostRewarded } from "@charmy.tech/react-native-admost";

export default function App() {
  useEffect(() => {
    const appId = "<your-app-id>";

    AdMost.initAdMost({
      appId: appId,
      userConsent: true,
      subjectToGDPR: false,
      subjectToCCPA: false,
      userChild: false,
    });
  }, []);

  // Rewarded events
  useEffect(() => {
    const adMostOnReadyEvent = AdMost.addRewardedListener.onReady((e) => {
      console.log("ON_READY", e);
      AdMostRewarded.showAd(e.zoneId, "TEST");
    });

    const adMostOnFailEvent = AdMost.addRewardedListener.onFail((e) => {
      console.log("ON_FAIL", e);
    });

    const adMostOnDismissEvent = AdMost.addRewardedListener.onDismiss((e) => {
      console.log("ON_DISMISS", e);
    });

    const adMostOnCompleteEvent = AdMost.addRewardedListener.onComplete((e) => {
      console.log("ON_COMPLETE", e);
    });

    const adMostOnShownEvent = AdMost.addRewardedListener.onShown((e) => {
      console.log("ON_SHOWN", e);
    });

    const adMostOnClickedEvent = AdMost.addRewardedListener.onClicked((e) => {
      console.log("ON_CLICKED", e);
    });

    const adMostOnStatusChangedEvent = AdMost.addRewardedListener.onStatusChanged((e) => {
      console.log("ON_STATUS_CHANGED", e);
    });

    return () => {
      adMostOnReadyEvent.remove();
      adMostOnFailEvent.remove();
      adMostOnDismissEvent.remove();
      adMostOnCompleteEvent.remove();
      adMostOnShownEvent.remove();
      adMostOnClickedEvent.remove();
      adMostOnStatusChangedEvent.remove();
    };
  });

  return (
    <SafeAreaView style={{ flex: 1 }}>
      <View style={{ flex: 1, justifyContent: "center" }}>
        <StatusBar barStyle="dark-content" backgroundColor="#ffffff" />
        <Button
          onPress={() => AdMostRewarded.loadAd("<admost-zone-id>")}
          title="Load Rewarded Ad"
          color="red"
        />
      </View>
    </SafeAreaView>
  );
}

Methods

NameParamsReturnDescription
loadAd(zoneId: string)voidLoad ad
destroyAd(zoneId: string)voidDestroy Ad
showAd(zoneId: string, tag: string)PromiseShow when ad is ready
isLoading(zoneId: string)PromiseAd is loading
isLoaded(zoneId: string)PromiseAd is loaded

Events

NameParams
ON_READY{ network: string; ecpm: number; zoneId: string }
ON_FAIL{ errorCode: number; errorDescription?: string(iOS); zoneId: string }
ON_DISMISS{ message?: string(Android); zoneId: string }
ON_COMPLETE{ network: string; zoneId: string }
ON_SHOWN{ network: string; zoneId: string }
ON_CLICKED{ network: string; zoneId: string }
ON_STATUS_CHANGED{ network: string; zoneId: string }
3.2.1

23 days ago

3.2.0

4 months ago

3.1.2

4 months ago

3.1.1

5 months ago

3.1.0

6 months ago

3.0.10

6 months ago

3.0.9

6 months ago

3.0.7

6 months ago

3.0.6

6 months ago

3.0.5

6 months ago

3.0.1

6 months ago

0.1.0

6 months ago