Google Analytcs Enhanced Ecommerce Tracking for Android issue
B

1

8

I've been trying to implement Enhanced Ecommerce Tracking, but no matter what I do the Ecommerce View in Google Analytcs web panel stays empty, i.e. no data is sent (apparently). All other data, Screen and Event tracking works as expected.

I'm following the official guides on installing google analytics and on implementing Enhanced Ecommerce tracking. Here are my settings:

in MyApplication class:

public class MyApplication extends Application {

  private Tracker mTracker;

  //....

    synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        mTracker = analytics.newTracker(R.xml.global_tracker);
        mTracker.set("&tid", GOOGLE_ANALYTICS_ID_VALUE);

    }
    return mTracker;
  }
 }

the R.xml.global_tracker:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="ga_sessionTimeout">300</integer>
    <bool name="ga_autoActivityTracking">false</bool>
    <string name="ga_sampleFrequency">100.0</string>
    <bool name="ga_reportUncaughtExceptions">true</bool>
    <integer name="ga_dispatchPeriod">30</integer>
</resources>

in BaseActivity class I have the trackEcommerce() method which I use in appropriate Activities/Fragments:

public void trackEcommerce(){

            String screenName = "eCommerce";
            String transactionID = "transactionID"; //some randomized value
            Double transactionRevenue = 0.0; //value of the transaction

            Tracker t = ((MyApplication) getApplication()).getDefaultTracker();

//send products
for (MyEcommerceItem item : myEcommerceItems) {
                    Product product = new Product()
                            .setId(item.getSku())
                            .setName(item.getTitle())
                            .setCategory(item.getType())
                            .setPrice(item.getPrice())
                            .setQuantity(item.getQuantity());

                    HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder().addProduct(product);
                    t.setScreenName(screenName);
                    t.send(builder.build());
                }


                //send transaction
                ProductAction productAction = new ProductAction(ProductAction.ACTION_CHECKOUT)
                        .setTransactionId(transactionID)
                        .setTransactionRevenue(transactionRevenue);

                HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder().setProductAction(productAction);
                t.setScreenName(screenName);
                t.send(builder.build());
}

The obvious question, can you see something that I'm doing wrong/some ideas on what I need to change?

Brewhouse answered 1/3, 2016 at 23:7 Comment(1)
Did you find any solution for this ?Reitman
K
1

You should use separate ecommerce_tracker tracker instead of using global tracker for Ecommerce Tracking. https://developers.google.com/analytics/devguides/collection/android/v4/advanced#multiple-trackers

public class MyApplication extends Application {
private Tracker mDefaultTracker;
private Tracker mEcommerceTracker;

//....

synchronized public Tracker getDefaultTracker() {
   if (mDefaultTracker == null) {
    GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
    mDefaultTracker = analytics.newTracker(R.xml.global_tracker);
    mDefaultTracker.set("&tid", GOOGLE_ANALYTICS_ID_VALUE);

   }
   return mDefaultTracker;
}

synchronized public Tracker getEcommerceTracker() {
   if (mEcommerceTracker == null) {
       GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
       mEcommerceTracker = analytics.newTracker(R.xml.ecommerce_tracker);

   }
   return mDefaultTracker;
   }
}

R.xml.ecommerce_tracker

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="ga_sessionTimeout">60</integer>
    <!--  The following value should be replaced with correct property id. -->
    <string name="ga_trackingId">UA-XXXXXX-Y</string>
</resources>

Also try to see what are the log outputs. Here is how to enable logs from GA https://developers.google.com/android/reference/com/google/android/gms/analytics/Logger

Kentkenta answered 2/3, 2016 at 9:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.