Implementacija praćenja interakcija s automatskim obavijestima
Da biste saznali više o cjelokupnom pristupu postavljanju push obavijesti Customer Insights - Journeys, posjetite pregled postavljanja push obavijesti.
Da biste omogućili automatske obavijesti Customer Insights - Journeys, morate izvršiti sljedeće korake:
- Konfiguracija aplikacije za automatske obavijesti
- Mapiranje korisnika za push obavijesti
- Registracija uređaja za push obavijesti
- Primanje push obavijesti na uređajima
- Izvješćivanje o interakciji za push obavijesti
Da bi izvijestila o otvorenim cijenama, aplikacija mora poslati te podatke natrag Customer Insights - Journeys.
Važno
Da biste pratili veze koje primatelji otvaraju u obavijestima, morate prikupiti pristanak za praćenje kupaca. Saznajte više o strategijama prikupljanja pristanka korisnika u: Customer Insights - Journeys Pregled upravljanja pristankom
Pošalji događaje primatelju Customer Insights - Journeys
Zatraži URL:
POST {PublicEndpoint}api/v1.0/orgs/<orgId>/pushdatareceiver/events
{
"TrackingId": "00000000-0000-0000-0000-000000000000",
"DeviceToken": "%DeviceToken",
"PushNotificationStatus": 1
}
Vraća: 202 ako je zahtjev točan, 400 u suprotnom
Ime/naziv | Opis |
---|---|
ID praćenja | Svaka obavijest ima identifikator praćenja u svojim podacima. Ovaj identifikator treba poslati radi praćenja događaja. |
Token uređaja | Jedinstveni token za mobilni uređaj koji registrira događaj. |
PushNotificationStatus | Šifra stanja događaja. '1' se vratio za otvoreni događaj. |
orgId | Identifikator Customer Insights - Journeys organizacije. |
Primjer Swift koda za slanje događaja u iOS
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()
}
Primjer Java koda za slanje događaja u Android
1. dio: Generirajte korisni teret
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. dio: HttpClient za slanje događaja poslužitelju
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);
}
});