- Description
- Quick start
- Integration
- Features
- Device identifiers collection
- Events tracking
- Custom events tracking
- Predefined event parameters
- Events buffering
- Install referrer tracking
- Push token tracking
- Reinstall Uninstall tracking
- APK preinstall tracking
- Deeplinks
- Offline mode
- Disable tracking
- Disable background tracking
- GDPR right to be forgotten
- Get referrer
- Get referrer parameter
- Web view tracking
- Requirements
Affise SDK is a software you can use to collect app usage statistics, device identifiers, deeplink usage, track install referrer.
Download latest Affise SDK (attribution-release.aar)
from releases page and place this binary to gradle application
module lib directory app/libs/attribution-release.aar
Add library as gradle file dependency to application module build script Add install referrer library
For kotlin build script build.gradle.kts use:
dependencies {
// ...
implementation(files("libs/attribution-release.aar"))
// Add install referrer
implementation("com.android.installreferrer:installreferrer:2.2")
}For groovy build script build.gradle use:
dependencies {
// ...
implementation files('libs/attribution-release.aar')
// Add install referrer
implementation 'com.android.installreferrer:installreferrer:2.2'
}After library is added as dependency sync project with gradle files and initialize.
For kotlin use:
class App : Application() {
override fun onCreate() {
super.onCreate()
val properties = AffiseInitProperties(
"Your appId", //Change to your app id
!BuildConfig.DEBUG, //Add your custom rule to determine if this is a production build
null, //Change to your partParamName
null, //Change to your partParamNameToken
null, //Change to your appToken
"Your secretId", //Change to your secretId
emptyList(), // Types to handles interception of clicks on activity
false // Affise metrics
)
Affise.init(this, properties)
}
}For java use:
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
AffiseInitProperties properties = new AffiseInitProperties(
"Your appId", //Change to your app id
!BuildConfig.DEBUG, //Add your custom rule to determine if this is a production build
null, //Change to your partParamName
null, //Change to your partParamNameToken
null, //Change to your appToken
"Your secretId", //Change to your secretId
Collections.emptyList(), // Types to handles interception of clicks on activity
false // Affise metrics
);
Affise.init(this, properties);
}
}For a minimal working functionality your app needs to declare internet permission:
<manifest>
<!-- ... -->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>To match users with events and data library is sending, these identifiers are collected:
AFFISE_APP_IDAFFISE_PKG_APP_NAMEAFFISE_APP_NAME_DASHBOARDAPP_VERSIONAPP_VERSION_RAWSTORETRACKER_TOKENTRACKER_NAMEFIRST_TRACKER_TOKENFIRST_TRACKER_NAMELAST_TRACKER_TOKENLAST_TRACKER_NAMEOUTDATED_TRACKER_TOKENINSTALLED_TIMEFIRST_OPEN_TIMEINSTALLED_HOURFIRST_OPEN_HOURINSTALL_BEGIN_TIMEINSTALL_FINISH_TIMEREFERRAL_TIMECREATED_TIMECREATED_TIME_MILLICREATED_TIME_HOURUNINSTALL_TIMEREINSTALL_TIMELAST_SESSION_TIMECPU_TYPEHARDWARE_NAMENETWORK_TYPEDEVICE_MANUFACTURERDEEPLINK_CLICKDEVICE_ATLAS_IDAFFISE_DEVICE_IDAFFISE_ALT_DEVICE_IDANDROID_IDANDROID_ID_MD5REFTOKENREFTOKENSREFERRERUSER_AGENTMCCODEMNCODEREGIONCOUNTRYLANGUAGEDEVICE_NAMEDEVICE_TYPEOS_NAMEPLATFORMAPI_LEVEL_OSAFFISE_SDK_VERSIONOS_VERSIONRANDOM_USER_IDAFFISE_SDK_POSTIMEZONE_DEVLAST_TIME_SESSIONTIME_SESSIONAFFISE_SESSION_COUNTLIFETIME_SESSION_COUNTAFFISE_DEEPLINKAFFISE_PART_PARAM_NAMEAFFISE_PART_PARAM_NAME_TOKENAFFISE_APP_TOKENLABELAFFISE_SDK_SECRET_IDUUIDAFFISE_APP_OPENEDPUSHTOKENEVENTSAFFISE_EVENTS_COUNT
For example, we want to track what items usually user adds to shopping cart. To send event first create it with following code
class Presenter {
fun onUserAddsItemsToCart(items: String) {
val items = JSONObject().apply {
put("items", "cookies, potato, milk")
}
Affise.sendEvent(AddToCartEvent(items, System.currentTimeMillis(), "groceries"))
}
}For java use:
class Presenter {
void onUserAddsItemsToCart(String items) {
JSONObject items = new JSONObject();
items.put("items", items);
Affise.sendEvent(new AddToCartEvent(items, System.currentTimeMillis(), "groceries"));
}
}With above example you can implement other events:
AchieveLevelEventAddPaymentInfoEventAddToCartEventAddToWishlistEventClickAdvEventCompleteRegistrationEventCompleteStreamEventCompleteTrialEventCompleteTutorialEventContentItemsViewEventDeepLinkedEventInitiatePurchaseEventInitiateStreamEventInviteEventLastAttributedTouchEventListViewEventLoginEventOpenedFromPushNotificationEventPurchaseEventRateEventReEngageEventReserveEventSalesEventSearchEventShareEventSpendCreditsEventStartRegistrationEventStartTrialEventStartTutorialEventSubscribeEventTravelBookingEventUnlockAchievementEventUnsubscribeEventUnsubscriptionEventUpdateEventViewAdvEventViewCartEventViewItemEventViewItemsEvent
Use any of custom events if default doesn't fit your scenario:
CustomId01EventCustomId02EventCustomId03EventCustomId04EventCustomId05EventCustomId06EventCustomId07EventCustomId08EventCustomId09EventCustomId10Event
To enrich your event with another dimension, you can use predefined parameters for most common cases. Add it to any event:
class Presenter {
fun onUserAddsItemsToCart(items: String) {
val items = JSONObject().apply {
put("items", "cookies, potato, milk")
}
val event = AddToCartEvent(items, System.currentTimeMillis()).apply {
addPredefinedParameter(PredefinedParameters.DESCRIPTION, "best before 2029")
}
Affise.sendEvent(event)
}
}For java use:
class Presenter {
void onUserAddsItemsToCart(String items) {
JSONObject items = new JSONObject();
items.put("items", items);
AddToCartEvent event = AddToCartEvent(items, System.currentTimeMillis());
event.addPredefinedParameter(PredefinedParameters.DESCRIPTION, "best before 2029");
Affise.sendEvent(event);
}
}In examples above PredefinedParameters.DESCRIPTION is used, but many others is available:
ADREV_AD_TYPECITYCOUNTRYREGIONCLASSCONTENTCONTENT_IDCONTENT_LISTCONTENT_TYPECURRENCYCUSTOMER_USER_IDDATE_ADATE_BDEPARTING_ARRIVAL_DATEDEPARTING_DEPARTURE_DATEDESCRIPTIONDESTINATION_ADESTINATION_BDESTINATION_LISTHOTEL_SCORELEVELMAX_RATING_VALUENUM_ADULTSNUM_CHILDRENNUM_INFANTSORDER_IDPAYMENT_INFO_AVAILABLEPREFERRED_NEIGHBORHOODSPREFERRED_NUM_STOPSPREFERRED_PRICE_RANGEPREFERRED_STAR_RATINGSPRICEPURCHASE_CURRENCYQUANTITYRATING_VALUERECEIPT_IDREGISTRATION_METHODRETURNING_ARRIVAL_DATERETURNING_DEPARTURE_DATEREVENUESCORESEARCH_STRINGSUBSCRIPTION_IDSUCCESSSUGGESTED_DESTINATIONSSUGGESTED_HOTELSTRAVEL_STARTTRAVEL_ENDUSER_SCOREVALIDATEDACHIEVEMENT_IDCOUPON_CODECUSTOMER_SEGMENTDEEP_LINKEVENT_STARTEVENT_ENDLATLONGNEW_VERSIONOLD_VERSIONREVIEW_TEXTTUTORIAL_IDVIRTUAL_CURRENCY_NAMEPARAM_01PARAM_02PARAM_03PARAM_04PARAM_05PARAM_06PARAM_07PARAM_08PARAM_09
Affise library will send any pending events with first opportunity, but if there is no network connection or device is disabled, events are kept locally for 7 days before deletion.
Install referrer tracking is supported automatically, no actions needed
To let affise track push token you need to receive it from your push service provider, and pass to Affise library. First add firebase integration to your app completing theese steps: https://firebase.google.com/docs/cloud-messaging/android/client
After you have done with firebase inegration, add to your cloud messaging service onNewToken method Affise.addPushToken(token)
class FirebaseCloudMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
// New token generated
Affise.addPushToken(token)
}
}Affise automaticly track reinstall events by using silent-push technology, to make this feature work, pass push token when it is recreated by user and on you application starts up
Affise.addPushToken(token)SDK is also supports scenario when APK is installed not from one of application markets, such as google play, huawei appgallery or amazon appstore
To use this feature, create file with name partner_key in your app assets directory, and write unique identifier inside, this key will be passed to our backend so you can track events by partner later in your Affise console.
To integrate applink support you need:
- add intent filter to one of your activities, replacing YOUR_AFFISE_APP_ID with id from your affise personal cabinet
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
<data android:host="YOUR_AFFISE_APP_ID.affattr.com" />
</intent-filter>- register applink callback right after Affise.init(..)
for kotlin:
Affise.init(..)
Affise.registerDeeplinkCallback { uri ->
val screen = uri.getQueryParameter("screen")
if(screen == "special_offer") {
// open special offer activity
} else {
// open another activity
}
// return true if deeplink is handled successfully
true
}for java:
Affise.registerDeeplinkCallback(uri -> {
String screen = uri.getQueryParameter("screen");
if (screen.equals("special_offer")) {
// open special offer screen
} else {
// open another activity
}
// return true if deeplink is handled successfully
return true;
});In some scenarious you would want to limit Affise network usage, to pause that activity call anywhere in your application following code after Affise init:
Affise.init(..)
Affise.setOfflineModeEnabled(enabled = true) // to enable offline mode
Affise.setOfflineModeEnabled(enabled = false) // to disable offline modeWhile offline mode is enabled, your metrics and other events are kept locally, and will be delivered once offline mode is disabled. Offline mode is persistent as Application lifecycle, and will be disabled with process termination automaticly. To check current offline mode status call:
Affise.isOfflineModeEnabled() // returns true or false describing current tracking stateTo disable any tracking activity, storing events and gathering device identifiers and metrics call anywhere in your application following code after Affise init:
Affise.init(..)
Affise.setTrackingEnabled(enabled = true) // to enable tracking
Affise.setTrackingEnabled(enabled = false) // to disable trackingBy default tracking is enabled.
While tracking mode is disabled, metrics and other identifiers is not generated locally. Keep in mind that this flag is persistent until app reinstall, and don't forget to reactivate tracking when needed. To check current status of tracking call:
Affise.isTrackingEnabled() // returns true or false describing current tracking stateTo disable any background tracking activity, storing events and gathering device identifiers and metrics call anywhere in your application following code after Affise init:
Affise.init(..)
Affise.setBackgroundTrackingEnabled(enabled = true) // to enable background tracking
Affise.setBackgroundTrackingEnabled(enabled = false) // to disable background trackingBy default background tracking is enabled.
While background tracking mode is disabled, metrics and other identifiers is not generated locally. Background tracking mode is persistent as Application lifecycle, and will be re-enabled with process termination automatically. To check current status of background tracking call:
Affise.isBackgroundTrackingEnabled() // returns true or false describing current background tracking stateUnder the EU's General Data Protection Regulation (GDPR): An individual has the right to have their personal data erased. To provide this functionality to user, as the app developer, you can call
Affise.init(..)
Affise.forget() // to forget users dataAfter processing such request our backend servers will delete all users data. To prevent library from generating new events, disable tracking just before calling Affise.forget:
Affise.init(..)
Affise.setTrackingEnabled(enabled = false)
Affise.forget() // to forget users dataUse the next public method of SDK
Affise.getReferrer()Use the next public method of SDK to get referrer parameter by
For kotlin:
Affise.getReferrerValue(ReferrerKey.CLICK_ID) { value ->
}For java:
Affise.getReferrerValue(ReferrerKey.CLICK_ID, value -> {
});In examples above ReferrerKey.CLICK_ID is used, but many others is available:
AD_IDCAMPAIGN_IDCLICK_IDAFFISE_ADAFFISE_AD_IDAFFISE_AD_TYPEAFFISE_ADSETAFFISE_ADSET_IDAFFISE_AFFC_IDAFFISE_CHANNELAFFISE_CLICK_LOOK_BACKAFFISE_COST_CURRENCYAFFISE_COST_MODELAFFISE_COST_VALUEAFFISE_DEEPLINKAFFISE_KEYWORDSAFFISE_MEDIA_TYPEAFFISE_MODELAFFISE_OSAFFISE_PARTNERAFFISE_REFAFFISE_SITE_IDAFFISE_SUB_SITE_IDAFFCPIDSUB_1SUB_2SUB_3SUB_4SUB_5
To integrate the library into the JavaScript environment, we added a bridge between JavaScript and the native SDK. Now you can send events and use the functionality of the native library directly from Webview. Here are step by step instructions:
// retreive webview from view hierarhy
val webView = findViewById<WebView>(R.Id.your_webview_id)
// make sure javascript is enabled
webView.javaScriptEnabled = true
// initialize webview with Affise native library
Affise.registerWebView(webView)
Other Javascript enviroment features is described below.
after webview is initialized you send events from JavaScript enviroment
var event = new AddPaymentInfoEvent(
{ card: 4138, type: 'phone' },
Date.now(),
'taxi'
);
event.addPredefinedParameter('affise_p_purchase_currency', 'USD');
Affise.sendEvent(event)
});Just like with native SDK, javascript enviroment also provides default events that can be passed from webview:
AchieveLevelEventAddPaymentInfoEventAddToCartEventAddToWishlistEventClickAdvEventCompleteRegistrationEventCompleteStreamEventCompleteTrialEventCompleteTutorialEventContentItemsViewEventConvertedOfferEventConvertedOfferFromRetryEventConvertedTrialEventConvertedTrialFromRetryEventCustomId01EventCustomId02EventCustomId03EventCustomId04EventCustomId05EventCustomId06EventCustomId07EventCustomId08EventCustomId09EventCustomId10EventDeepLinkedEventFailedOfferFromRetryEventFailedOfferiseEventFailedSubscriptionEventFailedSubscriptionFromRetryEventFailedTrialEventFailedTrialFromRetryEventInitialOfferEventInitialSubscriptionEventInitialTrialEventInitiatePurchaseEventInitiateStreamEventInviteEventLastAttributedTouchEventListViewEventLoginEventOfferInRetryEventOpenedFromPushNotificationEventPurchaseEventRateEventReEngageEventReactivatedSubscriptionEventRenewedSubscriptionEventRenewedSubscriptionFromRetryEventReserveEventSalesEventSearchEventShareEventSpendCreditsEventStartRegistrationEventStartTrialEventStartTutorialEventSubscribeEventSubscriptionEventSubscriptionInRetryEventTravelBookingEventTrialInRetryEventUnlockAchievementEventUnsubscribeEventUnsubscriptionEventUpdateEventViewAdvEventViewCartEventViewItemEventViewItemsEvent
Each event can be extended with custom event parameters. By calling addPredefinedParameter function you can pass predefined parameters name and value, for example:
var event = ...
event.addPredefinedParameter('affise_p_purchase_currency', 'USD');
Affise.sendEvent(event)
});If above event functionality still limits your usecase, you can allways extend Event class to override fields you are missing
class AchieveLevelEvent extends Event {
constructor(level, timeStampMillis, userData) {
super('AchieveLevel');
this.affise_event_first_for_user = false;
this.affise_event_user_data = userData;
this.affise_event_data = {
affise_event_achieve_level: level,
affise_event_achieve_level_timestamp: timeStampMillis
};
}
}});