共用方式為


實作推播通知互動追蹤

若要深入了解在 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); 
            } 
        });