Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytcs Enhanced Ecommerce Tracking for Android issue

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?

like image 622
ViksaaSkool Avatar asked Mar 01 '16 23:03

ViksaaSkool


People also ask

Is Google Analytics Good for ecommerce?

Google Analytics is an extremely powerful tool because of the amount of information provided to ecommerce merchants. Metrics like time on page and number of sessions are helpful data points to help you better understand your site's performance.


1 Answers

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

like image 159
pedo5000 Avatar answered Nov 09 '22 14:11

pedo5000