目录
此内容是否有帮助?

# 预置App推送接入文档

# 一、Android推送集成文档

# 1、FCM推送

# 1.1 上报 "推送 ID"

  • 在调用TA login或者切换账号之后上传FCM的Token。
//TASDK初始化
ThinkingAnalyticsSDK instance = ThinkingAnalyticsSDK.sharedInstance(this, APPID, SERVER_URL);
instance.login("user_id");
FirebaseMessaging.getInstance().getToken()
    .addOnCompleteListener(new OnCompleteListener<String>() {
        @Override
        public void onComplete(@NonNull Task<String> task) {
          if (!task.isSuccessful()) {
            Log.w(TAG, "Fetching FCM registration token failed", task.getException());
            return;
          }

          // Get new FCM registration token
          String token = task.getResult();
          JSONObject properties = new JSONObject();
          properties.put("fcm_token",token);
          instance.user_set(properties);
        }
 });
  • 在FCM Token变更时,更新用户属性:
@Override
public void onNewToken(@NonNull String token) {
    JSONObject properties = new JSONObject();
    properties.put("fcm_token",token);
    instance.user_set(properties);
}

# 1.2. 采集推送点击事件

在用户点击通知时上传推送点击事件,可以在onCreate或者onNewIntent获取推送参数。

public class PushOpenClickActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handlePushOpen();
    }
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handlePushOpen();
    }

    private void handlePushOpen() {
        try {
            Intent intent = getIntent();
            if (intent == null) {
                return;
            }
            Bundle bundle = intent.getExtras();
            if (bundle == null) {
                return;
            }
            String teExtras = bundle.getString("te_extras");
            TEPushUtil.trackAppOpenNotification(teExtras);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

# 1.3. 处理推送消息

建议以下两种方案二选一

  • 普通参数:调用handleTEPushAction方法。
  • 透传参数:调用handleTEPassThroughAction方法。
public class PushOpenClickActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handlePushOpen();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handlePushOpen();
    }

    private void handlePushOpen() {
        try {
            Intent intent = getIntent();
            if (intent == null) {
                return;
            }
            Bundle bundle = intent.getExtras();
            if (bundle == null) {
                return;
            }
            String teExtras = bundle.getString("te_extras");
            //如果处理普通参数 调用如下方法
            TEPushUtil.handleTEPushAction(teExtras);
            //如果处理透传参数 调用如下方法
            TEPushUtil.handleTEPassThroughAction(teExtras);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

# 2、极光推送

# 2.1 上报 "推送 ID"

  • 在调用TA login或者切换账号之后上传极光的Registration ID。
//登录或者切换账号之后调用
instance.login("user_id");

JSONObject properties = new JSONObject();
properties.put("jiguang_id",JPushInterface.getRegistrationID(context));
//instance为TA实例
instance.user_set(properties);
  • 在极光提供的onRegister接口中上传极光的Registration ID。
public class PushMessageReceiver extends JPushMessageReceiver {
    @Override
    public void onRegister(Context context, String registrationId) {
        JSONObject properties = new JSONObject();
        properties.put("jiguang_id",registrationId);
        //instance为TA实例
        instance.user_set(properties);
    }
}

# 2.2. 采集推送点击事件

非厂商通道可以在 onNotifyMessageOpened 接口中发送推送点击事件。

public class PushMessageReceiver extends JPushMessageReceiver {
    
    @Override
    public void onNotifyMessageOpened(Context context, NotificationMessage message) {
        //在通知点击回调中发送通知点击事件
        String te_extras = TAPushUtil.getPushExtras(message.notificationExtra);
        TEPushUtil.trackAppOpenNotification(te_extras);
    }
    
}

使用厂商通道的情况下,需要在厂商通道 Activity 的 onCreateonNewIntent 中拿到 intent,解析出相应的参数再发送推送点击事件

public class PushOpenClickActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handlePushOpen();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handlePushOpen();
    }

    private void handlePushOpen() {
        try {
            Intent intent = getIntent();
            if (intent == null) {
                return;
            }
            String pushData = null;
            // 华为通道消息数据
            if (getIntent().getData() != null) {
                pushData = getIntent().getData().toString();
            }
            // 小米、vivo、OPPO、FCM 通道消息数据(魅族会回调 onNotifyMessageOpened )
            if (TextUtils.isEmpty(pushData) && getIntent().getExtras() != null) {
                pushData = getIntent().getExtras().getString("JMessageExtra");
            }
            if (TextUtils.isEmpty(pushData)) {
                return;
            }
            JSONObject jsonObject = new JSONObject(pushData);
            // 推送消息附加字段
            String extras = jsonObject.optString("n_extras");
            String te_extras = TAPushUtil.getPushExtras(extras);
            TEPushUtil.trackAppOpenNotification(te_extras);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

# 2.3. 处理推送消息

建议以下两种方案二选一

  • 普通参数:调用handleTEPushAction方法。
  • 透传参数:调用handleTEPassThroughAction方法。

非厂商通道可以在 onNotifyMessageOpened 接口中处理推送消息。

public class PushMessageReceiver extends JPushMessageReceiver {
    
    @Override
    public void onNotifyMessageOpened(Context context, NotificationMessage message) {
        //在通知点击回调中发送通知点击事件
        String te_extras = TAPushUtil.getPushExtras(message.notificationExtra);
        //如果处理普通参数 调用如下方法
        TEPushUtil.handleTEPushAction(teExtras);
        //如果处理透传参数 调用如下方法
        TEPushUtil.handleTEPassThroughAction(teExtras);
    }
    
}

使用厂商通道的情况下,需要在厂商通道 Activity 的 onCreateonNewIntent 中拿到 intent,解析出相应的参数再处理推送消息

public class PushOpenClickActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handlePushOpen();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handlePushOpen();
    }

    private void handlePushOpen() {
        try {
            Intent intent = getIntent();
            if (intent == null) {
                return;
            }
            String pushData = null;
            // 华为通道消息数据
            if (getIntent().getData() != null) {
                pushData = getIntent().getData().toString();
            }
            // 小米、vivo、OPPO、FCM 通道消息数据(魅族会回调 onNotifyMessageOpened )
            if (TextUtils.isEmpty(pushData) && getIntent().getExtras() != null) {
                pushData = getIntent().getExtras().getString("JMessageExtra");
            }
            if (TextUtils.isEmpty(pushData)) {
                return;
            }
            JSONObject jsonObject = new JSONObject(pushData);
            // 推送消息附加字段
            String extras = jsonObject.optString("n_extras");
            String te_extras = TAPushUtil.getPushExtras(extras);
            //如果处理普通参数 调用如下方法
            TEPushUtil.handleTEPushAction(teExtras);
            //如果处理透传参数 调用如下方法
            TEPushUtil.handleTEPassThroughAction(teExtras);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

# 附录

# 客户端收到推送参数示例

以下仅展示客户端收到的扩展字段参数

{
    "te_extras": {
        //点击推送的跳转方式
        "ops_loading_type": "OPEN_APP",
        //透传参数
        "passthrough_params": {
                "param1": "abc",
                "param2": 101,
                "param3": [{
                        "subText1": "xyz",
                        "subText2": 2
                }]
        },
        //TE运营通道回执属性
        "#ops_receipt_properties": {
                "ops_task_id": "0082",
                "ops_project_id": 1,
                "ops_task_instance_id": "0082_20230331",
                "ops_push_language": "default",
                "ops_task_exec_detail_id": "55"
        }
    }
}

# trackAppOpenNotification

public static void trackAppOpenNotification(String extras) {
    try {
        if (TextUtils.isEmpty(extras)) {
            return;
        }
        JSONObject jsonObject = new JSONObject(extras);
        JSONObject properties = new JSONObject();
        Object obj = json.opt("#ops_receipt_properties");
        JSONObject ops = null;
        if (obj instanceof String) {
            ops = new JSONObject(( String ) obj);
        } else if (obj instanceof JSONObject) {
            ops = ( JSONObject ) obj;
        }
        properties.put("#ops_receipt_properties", ops);
        ThinkingAnalyticsSDK instance = ThinkingAnalyticsSDK.sharedInstance(null, "appId", "serverUrl");
        instance.track("ops_push_click", properties);
        //立马上报
        instance.flush();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

# handleTEPushAction

public static void handleTEPushAction(String extras) {
    try {
        if (TextUtils.isEmpty(extras)) {
            return;
        }
        JSONObject jsonObject = new JSONObject(extras);
        String type = jsonObject.optString("ops_loading_type");
        if ("OPEN_APP".equals(type)) {
            // TODO 处理打开 App 消息,--> 请启动 App
        } else if ("OPEN_URL".equals(type)) {
            String url = jsonObject.optString("ops_url");
            if (!TextUtils.isEmpty(url)) {
                // TODO 处理打开 URL 消息,--> 请处理 URL
            }
        } else if ("CUSTOMIZED".equals(type)) {
            String custom = jsonObject.optString("ops_customized");
            if (!TextUtils.isEmpty(custom)) {
                // TODO 处理自定义消息,--> 请处理自定义消息
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

# handleTEPassThroughAction

public static void handleTEPassThroughAction(String extras) {
    try {
        if (TextUtils.isEmpty(extras)) {
            return;
        }
        JSONObject jsonObject = new JSONObject(extras);
        String params = jsonObject.optString("passthrough_params");
        //params为透传参数,接下来是实现具体的业务逻辑
    } catch (Exception e) {
        e.printStackTrace();
    }
}

# TEPushUtil类

public class TEPushUtil {

    public static void trackAppOpenNotification(String extras) {
        try {
            if (TextUtils.isEmpty(extras)) {
                return;
            }
            JSONObject jsonObject = new JSONObject(extras);
            JSONObject properties = new JSONObject();
            Object obj = json.opt("#ops_receipt_properties");
            JSONObject ops = null;
            if (obj instanceof String) {
                ops = new JSONObject(( String ) obj);
            } else if (obj instanceof JSONObject) {
                ops = ( JSONObject ) obj;
            }
            properties.put("#ops_receipt_properties", ops);
            ThinkingAnalyticsSDK instance = ThinkingAnalyticsSDK.sharedInstance(null, "appId", "serverUrl");
            instance.track("ops_push_click", properties);
            //立马上报
            instance.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void handleTEPushAction(String extras) {
        try {
            if (TextUtils.isEmpty(extras)) {
                return;
            }
            JSONObject jsonObject = new JSONObject(extras);
            String type = jsonObject.optString("ops_loading_type");
            if ("OPEN_APP".equals(type)) {
                // TODO 处理打开 App 消息,--> 请启动 App
            } else if ("OPEN_URL".equals(type)) {
                String url = jsonObject.optString("ops_url");
                if (!TextUtils.isEmpty(url)) {
                    // TODO 处理打开 URL 消息,--> 请处理 URL
                }
            } else if ("CUSTOMIZED".equals(type)) {
                String custom = jsonObject.optString("ops_customized");
                if (!TextUtils.isEmpty(custom)) {
                    // TODO 处理自定义消息,--> 请处理自定义消息
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void handleTEPassThroughAction(String extras) {
        try {
            if (TextUtils.isEmpty(extras)) {
                return;
            }
            JSONObject jsonObject = new JSONObject(extras);
            String params = jsonObject.optString("passthrough_params");
            //params为透传参数,接下来是实现具体的业务逻辑
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getPushExtras(Object notificationExtras) {
        String teExtras = "";
        try {
            if (notificationExtras != null) {
                if (notificationExtras instanceof String) {
                    teExtras = new JSONObject((String) notificationExtras).optString("te_extras");
                } else if (notificationExtras instanceof Map) {
                    teExtras = new JSONObject((Map) notificationExtras).optString("te_extras");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return teExtras;
    }

}

# 二、iOS推送集成文档

# 1、FCM推送

# 1.1 上报 "推送 ID"

  • 在调用TA login或者切换账号之后上传FCM的Token。
NSString *appid = @"appid";
NSString *url = @"url";
TDConfig *config = [TDConfig new];
config.appid = appid;
config.configureURL = url;
ThinkingAnalyticsSDK *instance = [ThinkingAnalyticsSDK startWithConfig:config];

[[FIRMessaging messaging] tokenWithCompletion:^(NSString *token, NSError *error) {
      if (error != nil) {
        NSLog(@"Error getting FCM registration token: %@", error);
      } else {
        NSLog(@"FCM registration token: %@", token);
        [instance user_set:@{@"fcm_token": token}];
      }
}];

# 1.2. 采集推送点击事件

用户点击推送通知时,可以在系统的推送点击回调中发送推送点击事件。

// Handle notification messages after display notification is tapped by the user.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void(^)(void))completionHandler {
    NSDictionary *userInfo = response.notification.request.content.userInfo;
    trackAppOpenNotification(userInfo)
    completionHandler();
}

# 1.3. 处理推送消息

用户点击推送通知时,可以在系统的推送点击回调中获取推送参数。

建议以下两种方案二选一。

  • 普通参数:调用handleTEPushAction方法。
  • 透传参数:调用handlePassThroughAction方法。
// Handle notification messages after display notification is tapped by the user.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void(^)(void))completionHandler {
    NSDictionary *userInfo = response.notification.request.content.userInfo;
    //如果处理普通参数 调用如下方法
    handleTEPushAction(userInfo)
    //如果处理透传参数 调用如下方法
    handlePassThroughAction(userInfo)
    completionHandler();
}

# 2、极光推送

# 2.1 上报 "推送 ID"

  • 在调用TA login或者切换账号之后上传极光的Registration ID。
// login 之后,再次上报 registrationID
[instance login:<#登录 ID#>];
[instance user_set:@{@"jiguang_id": registrationID}];
  • 在 - registrationIDCompletionHandler: 回调中上传极光的Registration ID。
+// TA SDK 初始化之后,在极光回调中上报 registrationID
[JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
    [instance user_set:@{@"jiguang_id": registrationID}];
}];

# 2.2. 采集推送点击事件

//  iOS10以下,点击通知的回调
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
 
  [JPUSHService handleRemoteNotification:userInfo];
  trackAppOpenNotification(userInfo);
  completionHandler(UIBackgroundFetchResultNewData);
}
 
// iOS10以上,点击通知的回调
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler  API_AVAILABLE(ios(10.0)){
    // Required
    NSDictionary *userInfo = response.notification.request.content.userInfo;
    trackAppOpenNotification(userInfo);
    completionHandler();  // 系统要求执行这个方法
}

# 2.3. 处理推送消息

建议以下两种方案二选一。

  • 普通参数:调用handleTEPushAction方法。
  • 透传参数:调用handlePassThroughAction方法。
//  iOS10以下,点击通知的回调
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
 
  // Required, iOS 7 Support
  [JPUSHService handleRemoteNotification:userInfo];
  //如果处理普通参数 调用如下方法
  handleTEPushAction(userInfo)
  //如果处理透传参数 调用如下方法
  handlePassThroughAction(userInfo)
  completionHandler(UIBackgroundFetchResultNewData);
}
 
// iOS10以上,点击通知的回调
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler  API_AVAILABLE(ios(10.0)){
    // Required
    NSDictionary *userInfo = response.notification.request.content.userInfo;
    //如果处理普通参数 调用如下方法
    handleTEPushAction(userInfo)
    //如果处理透传参数 调用如下方法
    handlePassThroughAction(userInfo)
    completionHandler();  // 系统要求执行这个方法
}

# 附录

# 客户端收到推送参数示例

以下仅展示客户端收到的扩展字段参数

{
    "te_extras": {
        //点击推送的跳转方式
        "ops_loading_type": "OPEN_APP",
        //透传参数
        "passthrough_params": {
                "param1": "abc",
                "param2": 101,
                "param3": [{
                        "subText1": "xyz",
                        "subText2": 2
                }]
        },
        //TE运营通道回执属性
        "#ops_receipt_properties": {
                "ops_task_id": "0082",
                "ops_project_id": 1,
                "ops_task_instance_id": "0082_20230331",
                "ops_push_language": "default",
                "ops_task_exec_detail_id": "55"
        }
    }
}

# trackAppOpenNotification

+ (void)trackAppOpenNotification:(NSDictionary *)userInfo{
    NSMutableDictionary *pushProperties = [NSMutableDictionary dictionary]; // track 字典
    @try {
        NSData *jsonData = [userInfo[@"te_extras"] dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error;
        NSDictionary *sfDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
        if (!error && [sfDictionary isKindOfClass:NSDictionary.class]) {
            pushProperties[@"#ops_receipt_properties"] = sfDictionary[@"#ops_receipt_properties"];
        }
        [[ThinkingAnalyticsSDK sharedInstance]track:@"ops_push_click" properties:pushProperties];
        [[ThinkingAnalyticsSDK sharedInstance]flush];
    } @catch (NSException *exception) {
        
    }
}

# handleTEPushAction

+ (void)handleTEPushAction:(NSDictionary *)userInfo{
    NSMutableDictionary *pushProperties = [NSMutableDictionary dictionary]; // track 字典
    @try {
        NSString *jsonString = userInfo[@"te_extras"];
        NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error;
        NSDictionary *sfDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
        if (!sfDictionary || error) {
            return;
        }
        NSString *sf_landing_type = sfDictionary[@"ops_loading_type"];
        if ([sf_landing_type isEqualToString:@"OPEN_APP"]) {
            // 打开 App
        }
        else if ([sf_landing_type isEqualToString:@"OPEN_URL"]) {
            // 打开 URL
           NSString *url = sfDictionary[@"ops_url"];
        }
        else if ([sf_landing_type isEqualToString:@"CUSTOMIZED"]) {
           // 处理自定义消息
           NSString *customized = sfDictionary[@"ops_customized"];
        }
        
    } @catch (NSException *exception) {
        
    }
}

# handleTEPassThroughAction

+ (void)handleTEPassThroughAction:(NSDictionary *)userInfo{
    NSMutableDictionary *pushProperties = [NSMutableDictionary dictionary]; // track 字典
    @try {
        NSString *jsonString = userInfo[@"te_extras"];
        NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error;
        NSDictionary *sfDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
        if (!sfDictionary || error) {
            return;
        }
        NSString *params = sfDictionary[@"passthrough_params"];
        //params为透传参数,接下来是实现具体的业务逻辑
    } @catch (NSException *exception) {
        
    }
}

# 三、Unity推送集成文档

# 1、FCM推送

# 1.1 上报 "推送 ID"

  • 在调用 TE Login 或者切换账号之后上传 FCM 的 Token。
//TE SDK 初始化
ThinkingAnalyticsAPI.StartThinkingAnalytics("APP_ID", "SERVER_URL");
//设置账号 ID
ThinkingAnalyticsAPI.Login("ACCOUNT_ID");
//上报 FCM token 到 TE 系统
Firebase.Messaging.FirebaseMessaging.GetTokenAsync().ContinueWith(task => {
    var result = task.Result;
    ThinkingAnalyticsAPI.UserSet(new Dictionary<string, object>() { 
        { "fcm_token", task.Result } 
    });
});
  • 在 FCM Token 变更时,更新用户属性:
private void Start()
{
    // 注册 FCM Token 更新委托事件
    Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
    Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
}

public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token)
{
    //上报 FCM token 到 TE 系统
    ThinkingAnalyticsAPI.UserSet(new Dictionary<string, object>() { 
        { "fcm_token", token.Token } 
    });
}

# 1.2. 采集推送点击事件

在用户点击通知时上传推送点击事件,可以在 onCreate 或者 onNewIntent 获取推送参数。

private void Start()
{
    // 注册 FCM 消息委托事件
    Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
}

public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
{
    // 推送事件上报 (TETrackMessageReceived参见附录)
    this.TETrackMessageReceived(e.Message.Data);
}

# 1.3. 处理推送消息

建议以下两种方案二选一。

  • 普通参数:调用TEHandlePushAction方法。
  • 透传参数:调用TEHandlePassThroughAction方法。
private void Start()
{
    // 注册 FCM 消息委托事件
    Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
}

public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
{
    //如果处理普通参数 调用如下方法 (TEHandlePushAction参见附录)
    this.TEHandlePushAction(e.Message.Data);
    //如果处理透传参数 调用如下方法
    this.TEHandlePassThroughAction(e.Message.Data);
}

# 2、极光推送

# 1.1 上报 "推送 ID"

  • 在调用 TE Login 或者切换账号之后上传极光的 Registration ID。
//TE SDK 初始化
ThinkingAnalyticsAPI.StartThinkingAnalytics("APP_ID", "SERVER_URL");
//设置账号 ID
ThinkingAnalyticsAPI.Login("ACCOUNT_ID");
//上报 JPush Registration ID 到 TE 系统
string jiguangId = JPushBinding.GetRegistrationId();
ThinkingAnalyticsAPI.UserSet(new Dictionary<string, object>() { 
    { "jiguang_id", jiguangId } 
});
  • 在极光的 OnGetRegistrationId 接口中上传极光的 Registration ID。
void OnGetRegistrationId(string result)
{
    //上报 JPush Registration ID 到 TE 系统
    ThinkingAnalyticsAPI.UserSet(new Dictionary<string, object>() { 
        { "jiguang_id", jiguangId } 
    });
}

# 2.2. 采集推送点击事件

void OnReceiveNotification(string jsonStr)
{
    IDictionary<string, object> json = ThinkingAnalytics.Utils.TD_MiniJSON.Deserialize(jsonStr);
    if (json.ContainsKey("extras"))
    {
        object v = json["extras"];
        this.TETrackMessageReceived((IDictionary<string, string>)v);
    }
}

# 2.3. 处理推送消息

建议以下两种方案二选一。

  • 普通参数:调用TEHandlePushAction方法。
  • 透传参数:调用TEHandlePassThroughAction方法。
void OnOpenNotification(string jsonStr)
{
    Debug.Log("recv---openNotification---" + jsonStr);
    IDictionary<string, object> json = ThinkingAnalytics.Utils.TD_MiniJSON.Deserialize(jsonStr);
    if (json.ContainsKey("extras"))
    {
        object v = json["extras"];
        //如果处理普通参数 调用如下方法
        this.TEHandlePushAction((IDictionary<string, string>)v);
        //如果处理透传参数 调用如下方法
        this.TEHandlePassThroughAction((IDictionary<string, string>)v);
    }
}

# 附录

# 客户端收到推送参数示例

以下仅展示客户端收到的扩展字段参数

{
    "te_extras": {
        //点击推送的跳转方式
        "ops_loading_type": "OPEN_APP",
        //透传参数
        "passthrough_params": {
                "param1": "abc",
                "param2": 101,
                "param3": [{
                        "subText1": "xyz",
                        "subText2": 2
                }]
        },
        //TE运营通道回执属性
        "#ops_receipt_properties": {
                "ops_task_id": "0082",
                "ops_project_id": 1,
                "ops_task_instance_id": "0082_20230331",
                "ops_push_language": "default",
                "ops_task_exec_detail_id": "55"
        }
    }
}

# TETrackMessageReceived

private void TETrackMessageReceived(IDictionary<string, string> data)
{
    //上报 FCM message 事件到 TE 系统
    Dictionary<string, object> te_extras = ThinkingAnalytics.Utils.TD_MiniJSON.Deserialize(data["te_extras"]);
    Dictionary<string, object> properties = new Dictionary<string, object>();
    if (te_extras.ContainsKey("#ops_receipt_properties"))
    {
        properties.Add("#ops_receipt_properties", te_extras["#ops_receipt_properties"]);
    }
    ThinkingAnalytics.ThinkingAnalyticsAPI.Track("ops_push_click", properties);
    ThinkingAnalytics.ThinkingAnalyticsAPI.Flush();
}

# TEHandlePushAction

private void TEHandlePushAction(IDictionary<string, string> data)
{
    Dictionary<string, object> te_extras = ThinkingAnalytics.Utils.TD_MiniJSON.Deserialize(data["te_extras"]);
    string type = te_extras["ops_loading_type"].ToString();
    if ("OPEN_APP".Equals(type))
    {
        // 处理打开 App 消息,--> 请启动 App
    }
    else if ("OPEN_URL".Equals(type))
    {
        string url = te_extras["ops_url"].ToString();
        if (!string.IsNullOrEmpty(url))
        {
            // 处理打开 URL 消息,--> 请处理 URL
        }
    }
    else if ("CUSTOMIZED".Equals(type))
    {
        string custom = te_extras["ops_customized"].ToString();
        if (!string.IsNullOrEmpty(custom))
        {
            // 处理自定义消息,--> 请处理自定义消息
        }
    }
}

# TEHandlePassThroughAction

private void TEHandlePassThroughAction(IDictionary<string, string> data)
{
    Dictionary<string, object> te_extras = ThinkingAnalytics.Utils.TD_MiniJSON.Deserialize(data["te_extras"]);
    string params = te_extras["passthrough_params"].ToString();
    //params为透传参数,接下来是实现具体的业务逻辑
}