Additional Features
Attribution callback
You can set up a callback to be notified about attribution changes. We consider a variety of different sources for attribution, so we provide this information asynchronously.
Follow these steps to add the optional callback in your application:
-
Create a method with the signature of the delegate
Action<AdTraceAttribution>. -
After creating the
AdTraceConfigobject, call theadtraceConfig.setAttributionChangedDelegatewith the previously created method. You can also use a lambda with the same signature. -
If instead of using the
AdTrace.prefabtheAdTrace.csscript was added to anotherGameObject, be sure to pass the name of theGameObjectas the second parameter ofAdTraceConfig.setAttributionChangedDelegate.
Because the callback is configured using the AdTraceConfig instance, call adtraceConfig.setAttributionChangedDelegate before calling AdTrace.start.
using io.adtrace.sdk;
public class ExampleGUI : MonoBehaviour {
void OnGUI() {
if (GUI.Button(new Rect(0, 0, Screen.width, Screen.height), "callback")) {
AdTraceConfig adtraceConfig = new AdTraceConfig("{Your App Token}", AdTraceEnvironment.Sandbox);
adtraceConfig.setLogLevel(AdTraceLogLevel.Verbose);
adtraceConfig.setAttributionChangedDelegate(this.attributionChangedDelegate);
AdTrace.start(adtraceConfig);
}
}
public void attributionChangedDelegate(AdTraceAttribution attribution) {
Debug.Log("Attribution changed");
// ...
}
}
The callback function will be called when the SDK receives final attribution data. Within the callback function you have access to the attribution parameter. Here is a quick summary of its properties:
string trackerTokenthe tracker token of the current attributionstring trackerNamethe tracker name of the current attributionstring networkthe network grouping level of the current attributionstring campaignthe campaign grouping level of the current attributionstring adgroupthe ad group grouping level of the current attributionstring creativethe creative grouping level of the current attributionstring clickLabelthe click label of the current attributionstring adidthe Adtrace device identifierstring costTypethe cost type stringdouble? costAmountthe cost amountstring costCurrencythe cost currency string
User attribution
This callback, like an attribution callback, is triggered whenever the attribution information changes. Access your user's current attribution information whenever you need it by calling the following method of the AdTrace instance:
AdTraceAttribution attribution = AdTrace.getAttribution();
Current attribution information is available after our backend tracks the app install and triggers the attribution callback. It is not possible to access a user's attribution value before the SDK has been initialized and the attribution callback has been triggered.
Session and event callbacks
You can set up callbacks to notify you of successful and failed events and/or sessions.
Follow these steps to add the callback function for successfully tracked events:
// ...
AdTraceConfig adtraceConfig = new AdTraceConfig("{Your App Token}", AdTraceEnvironment.Sandbox);
adtraceConfig.setLogLevel(AdTraceLogLevel.Verbose);
adtraceConfig.setEventSuccessDelegate(EventSuccessCallback);
AdTrace.start(adtraceConfig);
// ...
public void EventSuccessCallback(AdTraceEventSuccess eventSuccessData) {
// ...
}
Add the following callback function for failed tracked events:
// ...
AdTraceConfig adtraceConfig = new AdTraceConfig("{Your App Token}", AdTraceEnvironment.Sandbox);
adtraceConfig.setLogLevel(AdTraceLogLevel.Verbose);
adtraceConfig.setEventFailureDelegate(EventFailureCallback);
AdTrace.start(adtraceConfig);
// ...
public void EventFailureCallback(AdTraceEventFailure eventFailureData) {
// ...
}
For successfully tracked sessions:
// ...
AdTraceConfig adtraceConfig = new AdTraceConfig("{Your App Token}", AdTraceEnvironment.Sandbox);
adtraceConfig.setLogLevel(AdTraceLogLevel.Verbose);
adtraceConfig.setSessionSuccessDelegate(SessionSuccessCallback);
AdTrace.start(adtraceConfig);
// ...
public void SessionSuccessCallback (AdTraceSessionSuccess sessionSuccessData) {
// ...
}
For failed tracked sessions:
// ...
AdTraceConfig adtraceConfig = new AdTraceConfig("{Your App Token}", AdTraceEnvironment.Sandbox);
adtraceConfig.setLogLevel(AdTraceLogLevel.Verbose);
adtraceConfig.setSessionFailureDelegate(SessionFailureCallback);
AdTrace.start(adtraceConfig);
// ...
public void SessionFailureCallback (AdTraceSessionFailure sessionFailureData) {
// ...
}
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:
string Messagethe message from the server or the error logged by the SDKstring Timestamptimestamp from the serverstring Adida unique device identifier provided by AdTraceDictionary<string, object> JsonResponsethe JSON object with the response from the server
Both event response data objects contain:
string EventTokenthe event token, if the package tracked was an eventstring CallbackIdthe custom defined callback ID set on an event object
Both event and session failed objects also contain:
bool WillRetryindicates there will be an attempt to resend the package at a later time
Device IDs
The Adtrace SDK lets you receive device identifiers.
IDFA (iOS Identifier)
To obtain the IDFA, call the function getIdfa of the AdTrace instance:
string idfa = AdTrace.getIdfa();
GPS AdId (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.
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 Google advertising ID can only be read in a background thread. If you call the method getGoogleAdId of the AdTrace instance with an Action<string> delegate, it will work in any situation:
AdTrace.getGoogleAdId((string googleAdId) => {
// ...
});
You will now have access to the Google advertising ID as the variable googleAdId.
AdId (Adtrace device identifier)
Our backend generates a unique Adtrace device identifier (known as an adid) for every device that has your app installed. In order to get this identifier, call this method on AdTrace instance:
String adid = AdTrace.getAdid();
Information about the adid is only available after our backend tracks the app install. It is not possible to access the adid value before the SDK has been initialized and the installation of your app has been successfully tracked.
Set external device ID (Experimental)
An external device identifier is a custom value that you can assign to a device or user. They can help you to recognize users across sessions and platforms. They can also help you to deduplicate installs by user so that a user isn't counted as multiple new installs.
You can also use an external device ID as a custom identifier for a device. This can be useful if you use these identifiers elsewhere and want to keep continuity.
This setting requires Adtrace SDK v2+ or later.
To set an external device ID, assign the identifier to the externalDeviceId property of your config instance. Do this before you initialize the Adtrace SDK.
AdTraceConfig.setExternalDeviceId("{Your-External-Device-Id}")
You need to make sure this ID is unique to the user or device depending on your use-case. Using the same ID across different users or devices could lead to duplicated data. Talk to your Adtrace representative for more information.
Default tracker
- Create a new tracker in your panel.
- Open your app delegate and set the default tracker of your config:
adtraceConfig.setDefaultTracker("{TrackerToken}");
-
Replace
{TrackerToken}with the tracker token you created in step one. Please note that the panel displays a tracker URL (includinghttp://app.adtrace.io/). In your source code, you should specify only the six or seven-character token and not the entire URL. -
Build and run your app. You should see a line like the following in your LogCat:
Default tracker: 'abc123'
Offline mode
Offline mode suspends transmission to our servers while retaining tracked data to be sent at a later point. While the Adtrace SDK is in offline mode, all information is saved in a file. Please be careful not to trigger too many events in offline mode.
Activate offline mode by calling setOfflineMode with the parameter true.
AdTrace.setOfflineMode(true);
Deactivate offline mode by calling setOfflineMode with false. When you put the Adtrace SDK back into online mode, all saved information is sent to our servers with the correct time information.
This setting is not remembered between sessions, meaning that the SDK is in online mode whenever it starts, even if the app was terminated in offline mode.
Disable tracking
You can disable Adtrace SDK tracking by invoking the method setEnabled 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 check if the Adtrace SDK is currently active with the method isEnabled. It is always possible to activate the Adtrace SDK by invoking setEnabled with the enabled parameter set to true.
Event buffering
If your app makes heavy use of event tracking, you might want to delay some network requests in order to send them in one batch every minute. You can enable event buffering with your AdTraceConfig instance:
AdTraceConfig adtraceConfig = new AdTraceConfig("{YourAppToken}", "{YourEnvironment}");
adtraceConfig.setEventBufferingEnabled(true);
AdTrace.start(adtraceConfig);
If nothing is set, event buffering is disabled by default.
Background tracking
The default behaviour of the Adtrace SDK is to pause sending network requests while the app is in the background. You can change this in your AdTraceConfig instance:
AdTraceConfig adtraceConfig = new AdTraceConfig("{YourAppToken}", "{YourEnvironment}");
adtraceConfig.setSendInBackground(true);
AdTrace.start(adtraceConfig);