Ads
Ads

Reputation: 6691

How to track Omniture Custom Traffic Variable in Android?

In Site Catalyst we have defined Custom Traffic Variable "Item Bought". Now how do i send request to update this custom variable from Android library? i don't find much help here

Please find my code below,

    public class TrackingHelper {
    private static final String TRACKING_RSID = "MY_TRACKING_RSID";
    private static final String TRACKING_SERVER = "MY_TRACKING_SERVER";
    static ADMS_Measurement measurement = null;

    public static void startActivity(Activity activity) {
        measurement = ADMS_Measurement.sharedInstance(activity);
        measurement.startActivity(activity);
    }

    public static void stopActivity() {
        measurement = ADMS_Measurement.sharedInstance();
        measurement.stopActivity();
    }

    public static void configureAppMeasurement(Activity activity) {
        if (measurement == null) {
            measurement = ADMS_Measurement.sharedInstance(activity);
            measurement.configureMeasurement(TRACKING_RSID, TRACKING_SERVER);
            measurement.setOfflineTrackingEnabled(true);
            measurement.setDebugLogging(true);
        }
    }

    public static void trackItemBought() {
        if (measurement != null) {
            measurement = ADMS_Measurement.sharedInstance();
            Hashtable<String, Object> contextData = new Hashtable<String, Object>();
            contextData.put("Item Bought", "Item Bought");
            measurement.setEvents("Item Bought");
            measurement.track(contextData);
        }
    }
}

Upvotes: 1

Views: 1111

Answers (2)

Sanchit
Sanchit

Reputation: 460

Just make the following change in your code.

public class TrackingHelper {
private static final String TRACKING_RSID = "MY_TRACKING_RSID";
private static final String TRACKING_SERVER = "MY_TRACKING_SERVER";
static ADMS_Measurement measurement = null;

public static void startActivity(Activity activity) {
    measurement = ADMS_Measurement.sharedInstance(activity);
    measurement.startActivity(activity);
}

public static void stopActivity() {
    measurement = ADMS_Measurement.sharedInstance();
    measurement.stopActivity();
}

public static void configureAppMeasurement(Activity activity) {
    if (measurement == null) {
        measurement = ADMS_Measurement.sharedInstance(activity);
        measurement.configureMeasurement(TRACKING_RSID, TRACKING_SERVER);
        measurement.setOfflineTrackingEnabled(true);
        measurement.setDebugLogging(true);
    }
}

public static void trackItemBought() {
    if (measurement != null) {
        measurement = ADMS_Measurement.sharedInstance();
        Hashtable<String, Object> contextData = new Hashtable<String, Object>();
        contextData.put("Item Bought", "Item Bought");
        measurement.setEvents("Item Bought");
        measurement.contextData(contextData);
        measurement.track();
    }
}

Upvotes: 0

Jenn
Jenn

Reputation: 410

I can't vouch for the android code, but here are some general thoughts:

When you send a context data variable, you send a name-value pair, so I suspect this line: contextData.put("Item Bought", "Item Bought"); Should be something more like this (I'm going to say the item being bought is a basketball): contextData.put("Item Bought", "Basketball");

Then someone with access to processing rules in SiteCatalyst will need to configure a rule to say that that variable ("Item Bought") belongs to its assigned custom traffic variable (prop14, for instance). http://www.jasonegan.net/2011/04/07/omniture-sitecatalyst-15-context-variables-processing-rules/ talks about how to do that a bit, but the article generally assumes you have a certain level of knowledge of SiteCatalyst.

Upvotes: 1

Related Questions