实施推送通知交互跟踪

要了解有关在 Customer Insights - Journeys 中设置推送通知的总体方法的更多信息,请访问推送通知设置概述

要在 Customer Insights - Journeys 中启用推送通知,您需要完成以下步骤:

  1. 推送通知应用程序配置
  2. 推送通知的用户映射
  3. 推送通知的设备注册
  4. 在设备上接收推送通知
  5. 推送通知的交互报告

为了报告开启率,应用程序需要将此数据发送回 Customer Insights - Journeys。

重要提示

要跟踪收件人在通知中打开的链接,必须收集客户跟踪同意书。 在 Customer Insights - Journeys:同意管理概述中了解有关收集客户同意的策略的更多信息

将事件发送到 Customer Insights - Journeys

请求 URL:

POST {PublicEndpoint}api/v1.0/orgs/<orgId>/pushdatareceiver/events
{ 

    "TrackingId": "00000000-0000-0000-0000-000000000000", 
    "DeviceToken": "%DeviceToken", 
    "PushNotificationStatus":  1

} 

返回:如果请求正确,为 202,否则为 400

客户 说明
TrackingId 每个通知的数据中都有一个跟踪标识符。 此标识符需要发送以用于事件跟踪。
DeviceToken 注册事件的移动设备的唯一令牌。
PushNotificationStatus 事件的状态代码。 开启的事件返回“1”。
orgId Customer Insights - Journeys 组织的标识符。

在 iOS 中发送事件的示例 Swift 代码

func createInteraction(typeInteraction: Int, trackingId: String) {
    if !trackingId.isEmpty || trackingId == "00000000-0000-0000-0000-000000000000" {
        return
    }
    let orgId = UserDefaults.standard.string(forKey: "organizationId2")
    let endP = UserDefaults.standard.string(forKey: "endpoint2")
    if orgId == nil || endP == nil {
        return
    }
    let url = URL(
        string: String(
            format: "https://%@/api/v1.0/orgs/%@/pushdatareceiver/events", endP ?? "", orgId ?? ""))!
    let session = URLSession.shared
    // now create the URLRequest object using the url object
    var request = URLRequest(url: url)
    request.httpMethod = "POST"  //set http method as POST
    // add headers for the request
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")  // change as per server requirements
    request.addValue("application/json", forHTTPHeaderField: "Accept")
    do {
        // convert parameters to Data and assign dictionary to httpBody of request
        let deviceToken = UserDefaults.standard.string(forKey: "deviceToken")
        let jsonBodyDict = [
            "PushNotificationStatus": String(typeInteraction), "DeviceToken": deviceToken,
            "TrackingId": trackingId,
        ]
        request.httpBody = try JSONSerialization.data(
            withJSONObject: jsonBodyDict, options: .prettyPrinted)
    } catch let error {
        print(error.localizedDescription)
        return
    }
    // create dataTask using the session object to send data to the server
    let task = session.dataTask(with: request) { data, response, error in
        if let error = error {
            print("Post Request Error: \(error.localizedDescription)")
            return
        }
        // ensure there is valid response code returned from this HTTP response
        guard let ttpResponse = response as? HTTPURLResponse,
            (200...299).contains(httpResponse.statusCode)
        else {
            print("Invalid Response received from the server")
            return
        }
        print("Interaction creation successful.")
    }
    // perform the task
    task.resume()
}


在 Android 中发送事件的示例 Java 代码

第 1 部分:生成有效负载

EventTrackingContract: 
public String toJsonString() { 
        JSONObject jsonObject = new JSONObject(); 
        try { 
            jsonObject.put("PushNotificationStatus", mEvent.toString()); 
            jsonObject.put("DeviceToken", mDeviceToken); 

            jsonObject.put("TrackingId", trackingId); 
        } catch (JSONException e) { 
            Log.d(LOG_TAG, "Json exception while creating event tracking contract: " + e.getMessage()); 
        } 
        return jsonObject.toString(); 
    } 
 
EventTypeEnum: 
public enum EventType {
    Opened(1); 
}

第 2 部分:用于将事件发送到服务器的 HttpClient

AsyncTask.execute(new Runnable() { 
            @Override 
            public void run() { 
                SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); 
                String hostname = sharedPreferences.getString(HOST_NAME, ""); 
                String organizationId = sharedPreferences.getString(ORGANIZATION_ID, ""); 
                final HashMap<String, String> headers = new HashMap<>(); 
                headers.put("Content-Type", "application/json"); 
                final EventTrackingContract eventTrackingContract = new EventTrackingContract(event); 
                Log.d(TAG, eventTrackingContract.toJsonString()); 
                String response = HttpClientWrapper.request(String.format("https://%s/api/v1.0/orgs/%s/pushdatareceiver/events" 

, hostname, organizationId, trackingId), 
                        "POST", headers, eventTrackingContract.toJsonString()); 
                Log.d(TAG, response); 
            } 
        });