-
-
Save abarisain/845458e2cf0edaf82e356d1117bf6f52 to your computer and use it in GitHub Desktop.
AT Internet Batch Integration - Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.batchlabs.android.atinernet; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.text.TextUtils; | |
import com.batch.android.Batch; | |
import com.batch.android.BatchPushPayload; | |
import com.atinternet.tracker.ATInternet; | |
import com.atinternet.tracker.Tracker; | |
public class ATInternetBatchIntegration | |
{ | |
public static void handleIntent(Intent intent) { | |
Bundle payload = intent.getBundleExtra(Batch.Push.PAYLOAD_KEY); | |
if (payload != null) { | |
String payloadXtor = payload.getString("xtor"); | |
if (payloadXtor != null) { | |
trackOpen(payloadXtor); | |
} else { | |
try { | |
BatchPushPayload batchPayload = BatchPushPayload.payloadFromReceiverExtras(payload); | |
String deeplink = batchPayload.getDeeplink(); | |
if (!TextUtils.isEmpty(deeplink)) { | |
handleDeeplink(deeplink); | |
} | |
} catch (BatchPushPayload.ParsingException e) { | |
// Safely ignore it | |
} | |
} | |
trackGenericOpen(); | |
} | |
} | |
private static void handleDeeplink(String rawDeeplink) { | |
Uri deeplink = Uri.parse(rawDeeplink); | |
String queryXtor = deeplink.getQueryParameter("xtor"); | |
if (!TextUtils.isEmpty(queryXtor)) { | |
trackOpen(queryXtor); | |
} else { | |
String fragment = deeplink.getFragment(); | |
if (fragment != null && fragment.length() > 5 && fragment.startsWith("xtor=")) { | |
trackOpen(fragment.substring(5)); | |
} | |
} | |
} | |
private static void trackGenericOpen() { | |
Tracker tracker = ATInternet.getInstance().getDefaultTracker(); | |
tracker.Screens().add("OpenedBatchPushNotification").sendView(); | |
} | |
private static void trackOpen(String xtor) { | |
Tracker tracker = ATInternet.getInstance().getDefaultTracker(); | |
tracker.Campaigns().add(xtor); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.batchlabs.android.atinernet; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
public class BaseActivity extends Activity | |
{ | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
ATInternetBatchIntegration.handleIntent(getIntent()); | |
} | |
@Override | |
protected void onNewIntent(Intent intent) | |
{ | |
super.onNewIntent(intent); | |
ATInternetBatchIntegration.handleIntent(intent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment