Android integration SDK of https://www.admitad.com/
Admitad help center: https://help.admitad.com/en/advertiser/topic/195-mobile-sdk/
You can find examples of use in this directory. You can open the Android project to see an example on how the admitad SDK can be integrated.
These are the minimal steps required to integrate the admitad SDK into your Android project. We are going to assume that you use Android Studio for your Android development and target an Android API level 14 (Ice Cream Sandwich) or later.
Add repository to the root gradle:
allprojects {
repositories {
jcenter()
google()
}
}
And this to the project's gradle:
implementation 'ru.tachos.admitadstatisticsdk:admitadstatisticsdk:1.6.5'
implementation 'com.android.installreferrer:installreferrer:1.0'
Important: This feature is supported if you are using AdmitadSDK v1.6.4 or above.
Admitad needs install referrer of the application to attribute installs properly. Google provides two methods to receive install referrers, so AdmitadSDK implements both of them to increase reliability.
Install referrer can be captured with a broadcast receiver using the Google Play Store INSTALL_REFERRER
intent.
If you are not using your own broadcast receiver add the following code into the application tag of your AndroidManifest.xml
.
<application
<receiver android:name="ru.tachos.admitadstatisticsdk.AdmitadBroadcastReceiver"
android:permission="android.permission.INSTALL_PACKAGES"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
Your application manifest file will look like one below
If you are using your own broadcast receiver implement its onReceive
method with the following code.
public void onReceive(Context context, Intent intent) {
// call Admitad receiver method
new AdmitadBroadcastReceiver().onReceive(context, intent);
/* your code */
}
Install referrer can be received from Google Play Referrer API. This is quicker and more reliable method. Please add the following line to the project's gradle:
implementation 'com.android.installreferrer:installreferrer:1.0'
- SDK is being initialized async, so you must call AdmitadTracker#initialize before using. We'd like to reccomend to initialize in the
Application#OnCreate
or in the launcher Activity inActivity#onCreate
. You have to pass context, postback key (non-null key is mandatory, exception is thrown otherwise), callback (optional)
AdmitadTracker.initialize(getApplicationContext(), YOUR_ANDROID_POSTBACK_KEY, new TrackerInitializationCallback() {
@Override
public void onInitializationSuccess() {
}
@Override
public void onInitializationFailed(Exception exception) {
}
});
- Example of handling deeplink:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onNewIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
if (intent.getData() != null) {
AdmitadTracker.getInstance().handleDeeplink(intent.getData());
}
}
- You can get current uid:
String admitadUid = AdmitadTracker.getInstance().getAdmitadUid();
- When
AdmitadTracker#initialize
is called, it's possible to start tracking even if sdk is not initialized, if sdk has any uid value, events will be stored and send ASAP. There're several events sdk is able to track:
AdmitadTracker.getInstance().logRegistration(*USER_ID*);
AdmitadTracker.getInstance().logUserReturn(*USER_ID*, *DAY_COUNT*);
AdmitadTracker.getInstance().logUserLoyalty(*USER_ID*, *OPEN_APP_COUNT*);
- To track confirmed purchase or paid order you have to create AdmitadOrder object using builder. e.g.:
final AdmitadOrder order = new AdmitadOrder.Builder("123", "100.00")
.setCurrencyCode("RUB")
.putItem(new AdmitadOrder.Item("Item1", "ItemName1", 300))
.putItem(new AdmitadOrder.Item("Item2", "ItemName2", 500))
.setUserInfo(new AdmitadOrder.UserInfo().putExtra("Surname", "UserSurname").putExtra("Age", "18"))
.build();
- You can customize your order using any combination of additional parameters.
You can initialize AdmitadOrder with extra parameter tarifCode. Then Admitad can apply this tariff to the order as defined in your agreement. To get tariff codes ask your Admitad account manager.
final AdmitadOrder order = new AdmitadOrder.Builder("123-ISBD-123", "500.00")
.setCurrencyCode("USD")
.putItem(new AdmitadOrder.Item("Item2", "ItemName2", 500))
.setTarifCode("first_time_book_buy")
.build();
You can initialize AdmitadOrder with extra parameter promocode. Then Admitad will show promocode for this order in statistics report of your campaign.
final AdmitadOrder order = new AdmitadOrder.Builder("123-ISBD-123", "500.00")
.setCurrencyCode("USD")
.putItem(new AdmitadOrder.Item("Item2", "ItemName2", 500))
.setPromocode("PROMO_SUPER_CODE")
.build();
- Then you can track buying events using
order
object:
AdmitadTracker.getInstance().logOrder(order);
AdmitadTracker.getInstance().logPurchase(order);
- You can pass extra parameter channel into method when tracking events. It's value will be used for deduplication on Admitad's side.
Set channel value to:
AdmitadTracker.ADMITAD_MOBILE_CHANNEL
if you intend to attribute event to Admitad- name of other affiliate network if you intend to attribute event to other network
AdmitadTracker.UNKNOWN_CHANNEL
if you don't know to whom the event should be attributed
String channel = AdmitadTracker.ADMITAD_MOBILE_CHANNEL; // setting admitad channel
AdmitadTracker.getInstance().logRegistration("TestRegistrationUid", channel);
- To subscribe for specific event, you can pass callbacks to any
log*
method, e.g.:
AdmitadTracker.getInstance().logRegistration(*USER_ID*, new TrackerListener() {
@Override
public void onSuccess(AdmitadEvent result) {
Log.d("AdmitadTracker", "Registration event sent successfully + " + result.toString());
}
@Override
public void onFailure(@AdmitadTrackerCode int errorCode, @Nullable String errorText) {
Log.d("AdmitadTracker", "Failed to send registration event: errorCode = " + errorCode + ", errorText = " + errorText);
}
});
- To subscribe for all events, you can call method
AdmitadTracker#addListener
. This method will be always called on sending.
AdmitadTracker.getInstance().addListener(new TrackerListener() {
@Override
public void onSuccess(AdmitadEvent result) {
Log.d("AdmitadTracker", "Event sent successfully + " + result.toString());
}
@Override
public void onFailure(@AdmitadTrackerCode int errorCode, @Nullable String errorText) {
Log.d("AdmitadTracker", "Failed to send event: errorCode = " + errorCode + ", errorText = " + errorText);
}
});
- See more examples in the test project
- To enable logs you can call any time:
AdmitadTracker.setLogEnabled(true);
The admitad SDK is licensed under the MIT License.
Copyright (c) 2018 Admitad GmbH
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.