react-native-adtrace
v2.3.0
Published
AdTrace React Native SDK
Downloads
2,254
Maintainers
Readme
Summary
This is the React Native SDK of AdTrace. You can read more about AdTrace at adtrace.io.
Table of contents
- Example app
- Basic integration
- Additional features
- AppTrackingTransparency framework
- SKAdNetwork framework
- Event tracking
- Subscription tracking
- Session parameters
- Attribution callback
- Session and event callbacks
- Disable tracking
- Offline mode
- Event buffering
- Measurement consent
- SDK signature
- Background tracking
- Device IDs
- Set external device ID
- Push token
- Track additional device identifiers
- Pre-installed trackers
- Deep linking
- License
Example app
There is an example app inside the example
directory.
Basic integration
We will describe the steps to integrate the AdTrace SDK into your React Native project. You can use any text editor or IDE for React Native development. There are no assumptions made regarding development environment.
Get the SDK
First, download the library from npm
:
$ npm install react-native-adtrace --save
or
$ yarn add react-native-adtrace
For iOS app make sure to go to ios
folder and install Cocoapods dependencies:
$ cd ios && pod install
After this AdTrace SDK should be successfully added to your app.
Integrate the SDK into your app
You should use the following import statement on top of your .js
file
import { AdTrace, AdTraceEvent, AdTraceConfig } from 'react-native-adtrace';
In your App.js
file, add the following code to initialize the AdTrace SDK:
constructor(props) {
super(props);
const adtraceConfig = new AdTraceConfig("{YourAppToken}", AdTraceConfig.EnvironmentSandbox);
AdTrace.create(adtraceConfig);
}
componentWillUnmount() {
AdTrace.componentWillUnmount();
}
Replace {YourAppToken}
with your app token. You can find this in your panel.
Depending on whether you build your app for testing or for production, you must set the environment with one of these values:
AdTraceConfig.EnvironmentSandbox
AdTraceConfig.EnvironmentProduction
Important: This value should be set to AdTraceConfig.EnvironmentSandbox
if and only if you or someone else is testing your app. Make sure to set the environment to AdTraceConfig.EnvironmentProduction
just before you publish the app. Set it back to AdTraceConfig.EnvironmentSandbox
when you start developing and testing it again.
We use this environment to distinguish between real traffic and test traffic from test devices. It is very important that you keep this value meaningful at all times!
AdTrace logging
You can increase or decrease the amount of logs you see in tests by calling setLogLevel
on your AdTraceConfig
instance with one of the following parameters:
adtraceConfig.setLogLevel(AdTraceConfig.LogLevelVerbose); // enable all logging
adtraceConfig.setLogLevel(AdTraceConfig.LogLevelDebug); // enable more logging
adtraceConfig.setLogLevel(AdTraceConfig.LogLevelInfo); // the default
adtraceConfig.setLogLevel(AdTraceConfig.LogLevelWarn); // disable info logging
adtraceConfig.setLogLevel(AdTraceConfig.LogLevelError); // disable warnings as well
adtraceConfig.setLogLevel(AdTraceConfig.LogLevelAssert); // disable errors as well
adtraceConfig.setLogLevel(AdTraceConfig.LogLevelSuppress); // disable all logging
AdTrace project settings
Once the AdTrace SDK has been added to your app, certain tweaks are going to be performed so that the AdTrace SDK can work properly. Below you can find a description of every additional thing that the AdTrace SDK performs after you've added it to your app and what needs to be done by you in order for AdTrace SDK to work properly.
Android permissions
The AdTrace SDK by default adds two permissions to your app's AndroidManifest.xml
file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
The INTERNET
permission might be needed by our SDK at any point in time. The ACCESS_WIFI_STATE
permission is needed by the AdTrace SDK if your app is not targeting the Google Play Store and doesn't use Google Play Services. If you are targeting the Google Play Store and you are using Google Play Services, the AdTrace SDK doesn't need this permission and, if you don't need it anywhere else in your app, you can remove it.
Add permission to gather Google advertising ID
If you are targeting Android 12 and above (API level 31), you need to add the com.google.android.gms.AD_ID
permission to read the device's advertising ID. Add the following line to your AndroidManifest.xml
to enable the permission.
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
For more information, see Google's AdvertisingIdClient.Info
documentation.
Google Play Services
Since August 1, 2014, apps in the Google Play Store must use the Google Advertising ID to uniquely identify devices. To allow the AdTrace SDK to use the Google Advertising ID, you must integrate Google Play Services.
In order to do this, open your app's build.gradle
file and find the dependencies
block. Add the following line:
implementation 'com.google.android.gms:play-services-analytics:18.0.1'
Note: The version of the Google Play Services library that you're using is not relevant to the AdTrace SDK, as long as the analytics part of the library is present in your app. In the example above, we just used the most recent version of the library at the time of writing.
To check whether the analytics part of the Google Play Services library has been successfully added to your app so that the AdTrace SDK can read it properly, you should start your app by configuring the SDK to run in sandbox
mode and set the log level to verbose
. After that, track a session or some events in your app and observe the list of parameters in the verbose logs which are being read once the session or event has been tracked. If you see a parameter called gps_adid
in there, you have successfully added the analytics part of the Google Play Services library to your app and our SDK is reading the necessary information from it.
In case you encounter any issue with attempts to read Google Advertising Identifier, feel free to open an issue in our Github repository or contact our support.
Proguard settings
If you are using Proguard, add these lines to your Proguard file:
-keep class io.adtrace.sdk.** { *; }
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
}
-keep public class com.android.installreferrer.** { *; }
Install referrer
In order to correctly attribute an install of your Android app to its source, AdTrace needs information about the install referrer. This can be obtained by using the Google Play Referrer API or by catching the Google Play Store intent with a broadcast receiver.
Important: The Google Play Referrer API is newly introduced by Google with the express purpose of providing a more reliable and secure way of obtaining install referrer information and to aid attribution providers in the fight against click injection. It is strongly advised that you support this in your application. The Google Play Store intent is a less secure way of obtaining install referrer information. It will continue to exist in parallel with the new Google Play Referrer API temporarily, but it is set to be deprecated in future.
Google Play Referrer API
In order to support this, add the following line to your app's build.gradle
file:
implementation 'com.android.installreferrer:installreferrer:2.2'
installreferrer
library is part of Google Maven repository, so in order to be able to build your app, you need to add Google Maven repository to your app's build.gradle
file if you haven't added it already:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Also, make sure that you have paid attention to the Proguard settings chapter and that you have added all the rules mentioned in it, especially the one needed for this feature:
-keep public class com.android.installreferrer.** { *; }
This feature is supported if you are using the AdTrace SDK v2.+ or above.
Google Play Store intent
The Google Play Store INSTALL_REFERRER
intent should be captured with a broadcast receiver. The AdTrace install referrer broadcast receiver is added to your app by default. For more information, you can check our native Android SDK README. You can see this in the AndroidManifest.xml
file which is part of our React Native plugin:
<receiver android:name="io.adtrace.sdk.AdTraceReferrerReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
Please bear in mind that, if you are using your own broadcast receiver which handles the INSTALL_REFERRER
intent, you don't need to add the AdTrace broadcast receiver to your manifest file. You can remove it, but inside your own receiver add the call to the AdTrace broadcast receiver as described in our Android guide.
Huawei Referrer API
As of v2.+, the AdTrace SDK supports install tracking on Huawei devices with Huawei App Gallery version 10.4 and higher. No additional integration steps are needed to start using the Huawei Referrer API.
iOS frameworks
Select your project in the Project Navigator. In the left hand side of the main view, select your target. In the tab Build Phases
, expand the group Link Binary with Libraries
. On the bottom of that section click on the +
button. Select below mentined frameworks and make sure to change the Status
of frameworks to Optional
. AdTrace SDK uses these frameworks with following purpose:
iAd.framework
- to support Apple Search Ads campaignsAdServices.framework
- to support Apple Search Ads campaignsAdSupport.framework
- to read iOS Advertising Id (IDFA) valueCoreTelephony.framework
- to read MCC and MNC informationStoreKit.framework
- to communicate withSKAdNetwork
frameworkAppTrackingTransparency.framework
- to ask for user's consent to be tracked and obtain status of that consent
Additional features
You can take advantage of the following features once the AdTrace SDK is integrated into your project.
AppTrackingTransparency framework
Note: This feature exists only in iOS platform.
For each package sent, the AdTrace backend receives one of the following four (4) states of consent for access to app-related data that can be used for tracking the user or the device:
- Authorized
- Denied
- Not Determined
- Restricted
After a device receives an authorization request to approve access to app-related data, which is used for user device tracking, the returned status will either be Authorized or Denied.
Before a device receives an authorization request for access to app-related data, which is used for tracking the user or device, the returned status will be Not Determined.
If authorization to use app tracking data is restricted, the returned status will be Restricted.
The SDK has a built-in mechanism to receive an updated status after a user responds to the pop-up dialog, in case you don't want to customize your displayed dialog pop-up. To conveniently and efficiently communicate the new state of consent to the backend, AdTrace SDK offers a wrapper around the app tracking authorization method described in the following chapter, App-tracking authorization wrapper.
App-tracking authorisation wrapper
Note: This feature exists only in iOS platform.
Adtrace SDK offers the possibility to use it for requesting user authorization in accessing their app-related data. Adtrace SDK has a wrapper built on top of the requestTrackingAuthorizationWithCompletionHandler: method, where you can as well define the callback method to get information about a user's choice. Also, with the use of this wrapper, as soon as a user responds to the pop-up dialog, it's then communicated back using your callback method. The SDK will also inform the backend of the user's choice. Integer value will be delivered via your callback method with the following meaning:
- 0:
ATTrackingManagerAuthorizationStatusNotDetermined
- 1:
ATTrackingManagerAuthorizationStatusRestricted
- 2:
ATTrackingManagerAuthorizationStatusDenied
- 3:
ATTrackingManagerAuthorizationStatusAuthorized
To use this wrapper, you can call it as such:
Adtrace.requestTrackingAuthorizationWithCompletionHandler(function(status) {
switch (status) {
case 0:
// ATTrackingManagerAuthorizationStatusNotDetermined case
break;
case 1:
// ATTrackingManagerAuthorizationStatusRestricted case
break;
case 2:
// ATTrackingManagerAuthorizationStatusDenied case
break;
case 3:
// ATTrackingManagerAuthorizationStatusAuthorized case
break;
}
});
Before calling the method, make sure that your iOS app's Info.plist
contains an entry for NSUserTrackingUsageDescription
key. In absence of that key and usage of this method, app will crash.
Get current authorisation status
Note: This feature exists only in iOS platform.
To get the current app tracking authorization status you can call getAppTrackingAuthorizationStatus
method of Adtrace
class that will return one of the following possibilities:
0
: The user hasn't been asked yet1
: The user device is restricted2
: The user denied access to IDFA3
: The user authorized access to IDFA-1
: The status is not available
SKAdNetwork framework
Note: This feature exists only in iOS platform.
If you have implemented the Adtrace iOS SDK v2.+ or above and your app is running on iOS 14 and above, the communication with SKAdNetwork will be set on by default, although you can choose to turn it off. When set on, Adtrace automatically registers for SKAdNetwork attribution when the SDK is initialized. If events are set up in the panel to receive conversion values, the Adtrace backend sends the conversion value data to the SDK. The SDK then sets the conversion value. After Adtrace receives the SKAdNetwork callback data, it is then displayed in the dashboard.
In case you don't want the Adtrace SDK to automatically communicate with SKAdNetwork, you can disable that by calling the following method on configuration object:
adtraceConfig.deactivateSKAdNetworkHandling();
Event tracking
You can use AdTrace to track all kinds of events. Let's say you want to track every tap on a button. Simply create a new event token in your [dashboard]. Let's say that event token is abc123
. You can add the following line in your button’s click handler method to track the click:
var adtraceEvent = new AdTraceEvent("abc123");
AdTrace.trackEvent(adtraceEvent);
Revenue tracking
If your users can generate revenue by tapping on advertisements or making In-App Purchases, then you can track those revenues with events. Let's say a tap is worth €0.01. You could track the revenue event like this:
var adtraceEvent = new AdTraceEvent("abc123");
adtraceEvent.setRevenue(2000.0, "Toman");
AdTrace.trackEvent(adtraceEvent);
Revenue deduplication
You can also add an optional transaction ID to avoid tracking duplicate revenues. The last ten transaction IDs are remembered, and revenue events with duplicate transaction IDs are skipped. This is especially useful for In-App Purchase tracking. You can see an example below.
If you want to track in-app purchases, please make sure to call the trackEvent
only if the transaction is finished and an item is purchased. That way you can avoid tracking revenue that is not actually being generated.
var adtraceEvent = new AdTraceEvent("abc123");
adtraceEvent.setRevenue(2000.0, "Toman");
adtraceEvent.setTransactionId("{YourTransactionId}");
AdTrace.trackEvent(adtraceEvent);
Note: Transaction ID is the iOS term, unique identifier for successfully finished Android In-App-Purchases is named Order ID.
Event Parameters
Similarly to the callback parameters mentioned above, you can also add parameters that AdTrace will transmit to the adtrace backend of your choice. You can export these values in the panel.
This works similarly to the callback parameters mentioned above, but can be added by calling the addEventParameter
method on your AdTraceEvent
instance.
var adtraceEvent = new AdTraceEvent("abc123");
adtraceEvent.addEventParameter("key", "value");
adtraceEvent.addEventParameter("foo", "bar");
AdTrace.trackEvent(adtraceEvent);
Note: Both parameters in this method must be strings. If either of the passed parameters is not a string, the key-value pair will not be added to the parameters list.
Callback identifier
You can also add custom string identifier to each event you want to track. This identifier will later be reported in event success and/or event failure callbacks to enable you to keep track on which event was successfully tracked or not. You can set this identifier by calling the setCallbackId
method on your AdTraceEvent
instance:
var adtraceEvent = new AdTraceEvent("abc123");
adtraceEvent.setCallbackId("Your-Custom-Id");
AdTrace.trackEvent(adtraceEvent);
Session parameters
Some parameters are saved to be sent in every event and session of the AdTrace SDK. Once you have added any of these parameters, you don't need to add them every time, since they will be saved locally. If you add the same parameter twice, there will be no effect.
These session parameters can be called before the AdTrace SDK is launched to make sure they are sent even on install. If you need to send them with an install, but can only obtain the needed values after launch, it's possible to delay the first launch of the AdTrace SDK to allow this behaviour.
Delay start
Delaying the start of the AdTrace SDK allows your app some time to obtain session parameters, such as unique identifiers, to be sent on install.
Set the initial delay time in seconds with the setDelayStart
field of the AdTraceConfig
instance:
adtraceConfig.setDelayStart(5.5);
In this case this will make the AdTrace SDK not send the initial install session and any event created for 5.5 seconds. After this time is expired or if you call sendFirstPackages()
of the AdTrace
instance in the meanwhile, every session parameter will be added to the delayed install session and events and the AdTrace SDK will resume as usual.
The maximum delay start time of the AdTrace SDK is 10 seconds.
Attribution callback
You can register a listener to be notified of tracker attribution changes. Due to the different sources considered for attribution, this information cannot be provided synchronously. The simplest way is to create a single anonymous listener which is going to be called each time your user's attribution value changes:
With the AdTraceConfig
instance, before starting the SDK, add the anonymous listener:
var adtraceConfig = new AdTraceConfig(appToken, environment);
adtraceConfig.setAttributionCallbackListener(function(attribution) {
// Printing all attribution properties.
console.log("Attribution changed!");
console.log(attribution.trackerToken);
console.log(attribution.trackerName);
console.log(attribution.network);
console.log(attribution.campaign);
console.log(attribution.adgroup);
console.log(attribution.creative);
console.log(attribution.clickLabel);
console.log(attribution.adid);
console.log(attribution.costType);
console.log(attribution.costAmount);
console.log(attribution.costCurrency);
});
AdTrace.create(adtraceConfig);
Within the listener function you have access to the attribution
parameters. Here is a quick summary of its properties:
trackerToken
the tracker token of the current attribution.trackerName
the tracker name of the current attribution.network
the network grouping level of the current attribution.campaign
the campaign grouping level of the current attribution.adgroup
the ad group grouping level of the current attribution.creative
the creative grouping level of the current attribution.clickLabel
the click label of the current attribution.adid
the AdTrace device identifier.costType
the cost type.costAmount
the cost amount.costCurrency
the cost currency.
Session and event callbacks
You can register a callback to be notified of successful and failed tracked events and/or sessions.
Follow the same steps as for attribution callback to implement the following callback function for successfully tracked events:
var adtraceConfig = new AdTraceConfig(appToken, environment);
adtraceConfig.setEventTrackingSucceededCallbackListener(function(eventSuccess) {
// Printing all event success properties.
console.log("Event tracking succeeded!");
console.log(eventSuccess.message);
console.log(eventSuccess.timestamp);
console.log(eventSuccess.eventToken);
console.log(eventSuccess.callbackId);
console.log(eventSuccess.adid);
console.log(eventSuccess.jsonResponse);
});
AdTrace.create(adtraceConfig);
The following callback function for failed tracked events:
var adtraceConfig = new AdTraceConfig(appToken, environment);
adtraceConfig.setEventTrackingFailedCallbackListener(function(eventFailure) {
// Printing all event failure properties.
console.log("Event tracking failed!");
console.log(eventFailure.message);
console.log(eventFailure.timestamp);
console.log(eventFailure.eventToken);
console.log(eventFailure.callbackId);
console.log(eventFailure.adid);
console.log(eventFailure.willRetry);
console.log(eventFailure.jsonResponse);
});
AdTrace.create(adtraceConfig);
For successfully tracked sessions:
var adtraceConfig = new AdTraceConfig(appToken, environment);
adtraceConfig.setSessionTrackingSucceededCallbackListener(function(sessionSuccess) {
// Printing all session success properties.
console.log("Session tracking succeeded!");
console.log(sessionSuccess.message);
console.log(sessionSuccess.timestamp);
console.log(sessionSuccess.adid);
console.log(sessionSuccess.jsonResponse);
});
AdTrace.create(adtraceConfig);
And for failed tracked sessions:
var adtraceConfig = new AdTraceConfig(appToken, environment);
adtraceConfig.setSessionTrackingFailedCallbackListener(function(sessionFailure) {
// Printing all session failure properties.
console.log("Session tracking failed!");
console.log(sessionFailure.message);
console.log(sessionFailure.timestamp);
console.log(sessionFailure.adid);
console.log(sessionFailure.willRetry);
console.log(sessionFailure.jsonResponse);
});
AdTrace.create(adtraceConfig);
The callback functions will be called after the SDK tries to send a package to the server. Within the callback you have access to a response data object specifically for the callback. Here is a quick summary of the session response data properties:
var message
the message from the server or the error logged by the SDK.var timestamp
timestamp from the server.var adid
a unique device identifier provided by AdTrace.var jsonResponse
the JSON object with the response from the server.
Both event response data objects contain:
var eventToken
the event token, if the package tracked was an event.var callbackId
the custom defined callback ID set on event object.
And both event and session failed objects also contain:
var willRetry
indicates there will be an attempt to resend the package at a later time.
Disable tracking
You can disable the AdTrace SDK from tracking by invoking the method setEnabled
of the AdTrace
instance with the enabled parameter as false
. This setting is remembered between sessions, but it can only be activated after the first session.
AdTrace.setEnabled(false);
You can verify if the AdTrace SDK is currently active with the method isEnabled
of the AdTrace
instance. It is always possible to activate the AdTrace SDK by invoking setEnabled
with the parameter set to true
.
Offline mode
You can put the AdTrace SDK in offline mode to suspend transmission to our servers while retaining tracked data to be sent later. When in offline mode, all information is saved in a file, so be careful not to trigger too many events while in offline mode.
You can activate offline mode by calling the method setOfflineMode
of the AdTrace
instance with the parameter true
.
AdTrace.setOfflineMode(true);
Conversely, you can deactivate offline mode by calling setOfflineMode
with false
. When the AdTrace SDK is put back in online mode, all saved information is send to our servers with the correct time information.
Unlike disabling tracking, this setting is not remembered between sessions. This means that the SDK is in online mode whenever it is started, even if the app was terminated in offline mode.
Event buffering
If your app makes heavy use of event tracking, you might want to delay some HTTP requests in order to send them in one batch every minute. You can enable event buffering with your AdTraceConfig
instance by calling setEventBufferingEnabled
method:
var adtraceConfig = new AdTraceConfig(appToken, environment);
adtraceConfig.setEventBufferingEnabled(true);
AdTrace.create(adtraceConfig);
SDK signature
An account manager must activate the AdTrace SDK signature. Contact AdTrace support if you are interested in using this feature.
If the SDK signature has already been enabled on your account and you have access to App Secrets in your AdTrace Dashboard, please use the method below to integrate the SDK signature into your app.
An App Secret is set by passing all secret parameters (secretId
, info1
, info2
, info3
, info4
) to setAppSecret
method of AdTraceConfig
instance:
var adtraceConfig = new AdTraceConfig(appToken, environment);
adtraceConfig.setAppSecret(secretId, info1, info2, info3, info4);
AdTrace.create(adtraceConfig);
Background tracking
The default behaviour of the AdTrace SDK is to pause sending HTTP requests while the app is in the background. You can change this in your AdTraceConfig
instance by calling setSendInBackground
method:
var adtraceConfig = new AdTraceConfig(appToken, environment);
adtraceConfig.setSendInBackground(true);
AdTrace.create(adtraceConfig);
If nothing is set, sending in background is disabled by default.
Device IDs
Certain services (such as Google Analytics) require you to coordinate device and client IDs in order to prevent duplicate reporting.
iOS advertising identifier
You can access the IDFA value of an iOS device by invoking the getIdfa
method of the AdTrace
instance and passing it a callback that will get triggered once the IDFA value has been obtained by the native iOS SDK:
AdTrace.getIdfa((idfa) => {
console.log("IDFA = " + idfa);
});
Google Play Services advertising identifier
The Google Play Services Advertising Identifier (Google advertising ID) is a unique identifier for a device. Users can opt out of sharing their Google advertising ID by toggling the "Opt out of Ads Personalization" setting on their device. When a user has enabled this setting, the AdTrace SDK returns a string of zeros when trying to read the Google advertising ID.
Important: If you are targeting Android 12 and above (API level 31), you need to add the
com.google.android.gms.AD_ID
permission to your app. If you do not add this permission, you will not be able to read the Google advertising ID even if the user has not opted out of sharing their ID.
The AdTrace SDK allows you to read the Google advertising identifier of the Android device on which your app is running. In order to do this, call the getGoogleAdId
method of the AdTrace
instance and pass your callback as a parameter. Once obtained by the native Android SDK, you will receive the Google advertising identifier value in your callback method:
AdTrace.getGoogleAdId((googleAdId) => {
console.log("Google Ad Id = " + googleAdId);
});
AdTrace device identifier
For every device with your app installed on it, the AdTrace backend generates a unique AdTrace device identifier (adid). In order to obtain this identifier, call the getAdid
method of the AdTrace
instance and pass your callback as a parameter to which the adid value will be sent once obtained:
AdTrace.getAdid((adid) => {
console.log("Adid = " + adid);
});
Note: Information about the adid is only available after an app installation has been tracked by the AdTrace backend. From that moment on, the AdTrace SDK has information about the device adid and you can access it with this method. So, it is not possible to access the adid value before the SDK has been initialized and installation of your app has been successfully tracked.
User attribution
This callback is triggered as described in the attribution callback section, providing you with information about a new attribution whenever it changes. If you want to access information about a user's current attribution status at any other time, you can make a call to the getAttribution
method of the AdTrace
instance and pass your callback as a parameter to which the attribution value will be sent once obtained:
AdTrace.getAttribution((attribution) => {
console.log("Tracker token = " + attribution.trackerToken);
console.log("Tracker name = " + attribution.trackerName);
console.log("Network = " + attribution.network);
console.log("Campaign = " + attribution.campaign);
console.log("Adgroup = " + attribution.adgroup);
console.log("Creative = " + attribution.creative);
console.log("Click label = " + attribution.clickLabel);
console.log("Adid = " + attribution.adid);
});
Note: Information about a user's current attribution status is only available after an app installation has been tracked by the AdTrace backend and the attribution callback has been triggered. From that moment on, the AdTrace SDK has information about a user's attribution status and you can access it with this method. So, it is not possible to access a user's attribution value before the SDK has been initialized and an attribution callback has been triggered.
Push token
To send us the push notification token, add the following call to AdTrace whenever you get your token in the app or when it gets updated:
AdTrace.setPushToken("YourPushNotificationToken");
Push tokens are used for Audience Builder and client callbacks, and they are required for the upcoming uninstall tracking feature. Note: in order to handle the case where a silent push sent, check this link.
Pre-installed trackers
If you want to use the AdTrace SDK to recognize users that found your app pre-installed on their device, follow these steps.
Create a new tracker in your panel.
Open your app delegate and add set the default tracker of your
AdTraceConfig
instance:var adtraceConfig = new AdTraceConfig(appToken, environment); adtraceConfig.setDefaultTracker("{TrackerToken}"); AdTrace.create(adtraceConfig);
Replace {TrackerToken}
with the tracker token you created in step 2. Please note that the dashboard displays a tracker
URL (including http://app.adtrace.io/
). In your source code, you should specify only the six-character token and not the
entire URL.
Build and run your app. You should see a line like the following in the app's log output:
Default tracker: 'abc123'
Deep linking
If you are using the AdTrace tracker URL with an option to deep link into your app from the URL, there is the possibility to get info about the deep link URL and its content. Hitting the URL can happen when the user has your app already installed (standard deep linking scenario) or if they don't have the app on their device (deferred deep linking scenario).
Standard deep linking scenario
To support deep linking in Android, the app's AndroidManifest.xml
file will need to be modified. Please refer to this page of our Android SDK for the needed modifications to AndroidManifest.xml
.
To support deep linking in iOS 8 or earlier, the app's Info.plist
file will need to be modified. Please refer to this page of our iOS SDK for the needed modifications to Info.plist
.
To support deep linking in iOS 9 or later, your app would have to handle Universal Links. Please refer to this page of our iOS SDK for the needed modifications.
After that, refer to this page of the React Native offical docs for instructions on how to support both platforms and obtain deep link URL in your JavaScript code.
Deferred deep linking scenario
While deferred deep linking is not supported out of the box on Android and iOS, our AdTrace SDK makes it possible.
In order to get info about the URL content in a deferred deep linking scenario, you should set a callback method on the AdTraceConfig
object which will receive one parameter where the content of the URL will be delivered. You should set this method on the config object by calling the method setDeferredDeeplinkCallbackListener
:
var adtraceConfig = new AdTraceConfig(appToken, environment);
adtraceConfig.setDeferredDeeplinkCallbackListener(function(deeplink) {
console.log("Deferred deep link URL content: " + deeplink);
});
AdTrace.create(adtraceConfig);
In the deferred deep linking scenario, there is one additional setting which can be set on the AdTraceConfig
object. Once the AdTrace SDK gets the deferred deep link info, we are offering you the possibility to choose whether our SDK should open this URL or not. You can choose to set this option by calling the setShouldLaunchDeeplink
method on the config object:
var adtraceConfig = new AdTraceConfig(appToken, environment);
adtraceConfig.setShouldLaunchDeeplink(true);
// or adtraceConfig.setShouldLaunchDeeplink(false);
adtraceConfig.setDeferredDeeplinkCallbackListener(function(deeplink) {
console.log("Deferred deep link URL content: " + deeplink);
});
AdTrace.create(adtraceConfig);
If nothing is set, the AdTrace SDK will always try to launch the URL by default.
Reattribution via deep links
AdTrace enables you to run re-engagement campaigns by using deep links. For more information on this, please check our [official docs][reattribution-with-deeplinks].
If you are using this feature, in order for your user to be properly reattributed, you need to make one additional call to the AdTrace SDK in your app. Once you have received deep link content information in your app, add a call to appWillOpenUrl
method of the AdTrace
instance. By making this call, the AdTrace SDK will try to find if there is any new attribution info inside of the deep link and if any, it will be sent to the AdTrace backend. If your user should be reattributed due to a click on the AdTrace tracker URL with deep link content in it, you will see the attribution callback in your app being triggered with new attribution info for this user.
Call to the appWillOpenUrl
method in a React component would look like this:
componentDidMount() {
Linking.addEventListener('url', this.handleDeepLink);
Linking.getInitialURL().then((url) => {
if (url) {
this.handleDeepLink({ url });
}
})
}
componentWillUnmount() {
Linking.removeEventListener('url', this.handleDeepLink);
}
handleDeepLink(event) {
AdTrace.appWillOpenUrl(event.url);
}
License
The AdTrace SDK is licensed under the MIT License.
Copyright (c) AdTrace io, https://www.adtrace.io
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.