1. Record Activation Events

It is recommended to call the activation event in the native code

You can call the trackAppInstall() method to record the activation event. Calling this method multiple times will only trigger the activation event on the first call.

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(); }
CODE

In the onRequestPermissionsResult() method of the permission callback, whether the permission request is successful or not, you should call trackAppInstall():

@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"); // 触发激活事件 SensorsDataAPI.sharedInstance().trackAppInstall(properties); } catch (Exception e) { e.printStackTrace(); } }
CODE

The permission request should call trackAppInstall(), whether it is successful or not:

You can call the trackAppInstall method after initializing the SDK to record the activation event. Calling this method multiple times will only trigger the activation event on the first call:

// 需要 #import <AppTrackingTransparency/AppTrackingTransparency.h> if (@available(iOS 14, *)) { [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { // iOS 14 及以上记录激活事件。 // 如果您之前使用 - trackInstallation:  触发的激活事件,需要继续保持原来的调用,无需改为 - trackAppInstall: , 否则会导致激活事件数据分离。 [[SensorsAnalyticsSDK sharedInstance] trackAppInstallWithProperties:@{@"DownloadChannel": @"AppStore"}]; }]; } else { // iOS 13 及以下记录激活事件 [[SensorsAnalyticsSDK sharedInstance] trackAppInstallWithProperties:@{@"DownloadChannel": @"AppStore"}]; }
CODE

If the original activation event name is not $AppInstall, you need to use the virtual event to combine the original activation event with $AppInstall for analysis. For more information, please consult with the Sensors Data technical support.