Channel Tracking and Advertising (Android)
|
Collect
1. Record activation event
Can call trackAppInstall() method records activation events, and calling this method multiple times only triggers the activation event on the first call. IntrackAppInstall() methodThe AndroidId, MEID, IMEI, MAC, OAID identifiers are attempted to improve matching accuracy.
if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.M){ if (ActivityCompat.checkSelfPermission(this, "android.permission.READ_PHONE_STATE") != PackageManager.PERMISSION_GRANTED) { // 6.0 以上,无权限时,先申请 READ_PHONE_STATE 权限。 ActivityCompat.requestPermissions(this, new String[]{"android.permission.READ_PHONE_STATE"}, 100); } else { // 6.0 以上,有权限时,直接触发激活事件。 trackAppInstall(); } } else { // 6.0 以下,无须申请权限,直接触发激活事件。 trackAppInstall(); }
Callback in permissions onRequestPermissionsResult() method, Callback is invoked regardless of whether permission application succeeds or failstrackAppInstall():
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == 100) { // 申请权限结果回调时(无论申请权限成功失败),都需要触发激活事件。 trackAppInstall(); } } /** * 记录激活事件 */ private void trackAppInstall() { try { JSONObject properties = new JSONObject(); //这里的 DownloadChannel 负责记录下载商店的渠道,值应传入具体应用商店包的标记。如果没有为不同商店打多渠道包,则可以忽略该属性的代码示例。 properties.put("DownloadChannel", "XXX"); // 触发激活事件 // 如果您之前使用 trackInstallation() 触发的激活事件,需要继续保持原来的调用,无需改为 trackAppInstall(),否则会导致激活事件数据分离。 SensorsDataAPI.sharedInstance().trackAppInstall(properties); } catch (Exception e) { e.printStackTrace(); } }
- If the original activation event name is not $AppInstall, need useCustom Eventsto combine the original activation event and $AppInstall to analyze the data, and consult technical support for details
- For more information on channel tracking, please refer toChannel tracking.
2. Track and channel match and return
From Androidv4.1.0 start The SDK supports custom events triggered by the track method to add logic to channel properties.
2.1. Usage method
Called when initializing the SDKSAConfigOptions.enableAutoAddChannelCallbackEvent(true) method to enable the function, which is disabled by default. An example is as follows:
private void initSensorsDataAPI() { SAConfigOptions configOptions = new SAConfigOptions(SA_SERVER_URL); configOptions.setAutoTrackEventType(SensorsAnalyticsAutoTrackEventType.APP_START | SensorsAnalyticsAutoTrackEventType.APP_END | SensorsAnalyticsAutoTrackEventType.APP_VIEW_SCREEN | SensorsAnalyticsAutoTrackEventType.APP_CLICK) .enableTrackAppCrash() .enableAutoAddChannelCallbackEvent(true) //开启新渠道功能 SensorsDataAPI.startWithConfigOptions(this, configOptions); }
2.2. effect
Can useSensorsDataAPI.shareInstance().track(eventName) to channel back to specific events.
- 当次安装、First triggerreturn event, Record events and channel match and return.
- Contemporaneous installation、retriggerreturn event, events are recorded without channel matching and backtracking.
- Unloading and reloading、First triggerreturn event, Record events and channel match and return.
p.s. The above rules apply to events with the same name, and different events do not affect each other.
3. Advertising related events are reported directly
Android SDK v6.7.4 or later supports reporting ad-related events directly to the AD server. The specific usage is as follows:
SecreteKey secreteKey = new SecreteKey("秘钥", 秘钥版本, "AES", "RSA"); List<String> list = new ArrayList<>(); list.add("$AppInstall"); configOptions.setAdvertConfig(new SAAdvertisingConfig("广告数据接收地址", list, secreteKey)); SensorsDataAPI.startWithConfigOptions(this, configOptions);
- If the event is not encrypted when reporting to the ad server, the SAAdvertisingConfig can be initialized with a null key
- When initializing SAAdvertisingConfig, the reporting address and event collection are required fields
- Please contact customer service or the delivery team to obtain the reporting address and encryption key for the ad server
4. Ad Retargeting
Starting from Android SDK v6.7.6, ad retargeting functionality is supported. Refer to the following for specific usage:
SAConfigOptions configOptions = new SAConfigOptions(SA_SERVER_URL); SAAdvertisingConfig advertisingConfig = new SAAdvertisingConfig(); // 开启广告再营销 advertisingConfig.enableRemarketing(); // 如果 SDK 需要延迟初始化,请记录拉起 App 时的 url,并在初始化时传入 SDK,SDK 如果非延迟初始化,无需设置此项 advertisingConfig.setWakeupUrl("延迟初始化SDK 时唤起 app 的 url"); configOptions.setAdvertConfig(advertisingConfig); SensorsDataAPI.startWithConfigOptions(this, configOptions);
Note: The content of this document is a technical document that provides details on how to use the Sensors product and does not include sales terms; the specific content of enterprise procurement products and technical services shall be subject to the commercial procurement contract.