Skip to content

Instantly share code, notes, and snippets.

@cami7ord
Created December 14, 2015 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cami7ord/e0e90b98cbf2f06f8fd3 to your computer and use it in GitHub Desktop.
Save cami7ord/e0e90b98cbf2f06f8fd3 to your computer and use it in GitHub Desktop.
package com.mercadoni.user.android.managers;
import android.content.Context;
import android.os.Bundle;
import com.ad4screen.sdk.A4S;
import com.ad4screen.sdk.analytics.Cart;
import com.ad4screen.sdk.analytics.Item;
import com.ad4screen.sdk.analytics.Purchase;
import java.text.SimpleDateFormat;
import java.util.Date;
public class AccengageManager {
private static AccengageManager ourInstance = new AccengageManager();
public static AccengageManager getInstance() {
return ourInstance;
}
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz");
private AccengageManager() {
}
// PERSONALIZED EVENTS
public void registerUserCountry(Context context, String email, String country, String city) {
A4S.get(context).trackEvent(1000, email, country, city);
}
public void registerUserPurchase(Context context, String email, String country, String city, String purchaseId, String total) {
A4S.get(context).trackEvent(1001, email, country, city, purchaseId, total);
}
public void registerRetailerOnCart(Context context, String email, String cartId, String retailerName, String retailerLocation) {
A4S.get(context).trackEvent(1002, email, cartId, retailerName, retailerLocation);
}
// UPDATE DEVICE INFORMATION
public void updateDeviceInformation(Context context, String firstName, String countryCode, int purchaseCounter, Date lastPurchase) {
Bundle bundle = new Bundle();
bundle.putString("firstName", firstName);
bundle.putString("countryCode", countryCode);
bundle.putInt("purchaseCounter", purchaseCounter);
bundle.putString("lastPurchaseDate", dateFormat.format(lastPurchase));
A4S.get(context).updateDeviceInfo(bundle);
}
// DEFAULT EVENTS
// Not being used since we dont need to know the products bought for the moment.
public void trackAddToCartEvent(Context context, String purchaseId, String purchaseCurrency, long totalPrice) {
Item item = new Item("ArticleID", "Label", "Category", "Currency", 12.30, 1);
Cart cart = new Cart("CartId", item);
A4S.get(context).trackAddToCart(cart);
}
public void trackPurchaseEvent(Context context, String purchaseId, String purchaseCurrency, String totalPrice) {
Purchase purchase = new Purchase(purchaseId, purchaseCurrency, Long.parseLong(totalPrice));
A4S.get(context).trackPurchase(purchase);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment