Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set appVersion for Google Analytics Event tracking

When I try to set the appVersion in google analytics, then my event tracking stops working. Specifically, I'm trying to include the app version with event tracking so I can know which version of the app caused an event.

I've tried setting the app version like this:

ga('set', 'appVersion', app.version);

I've tried like this:

ga('send', 
   'event', 
   eventCategory, 
   eventAction, 
   {'page': pageName, 'appVersion' : app.version });

And I've also tried the alternative syntax:

ga('send', 
   {'hitType' : 'event',
    'eventCategory' : eventCategory,
    'eventAction' : eventAction,
    'page' : pageName,
    'appVersion' : app.version});

If I include appVersion, then event tracking stops working. No events show in realtime and no show the next day in the Behavior/Events section. The PageViews still work though.

As requested in the comments, I am editing to add in my event tracking code. It's been through several variations while I tried solve this problem. Here's what it looks like currently.

var app = {
    trackEvent: function (pageName, eventCategory, eventAction, optionalEventLabel, optionalEventValue) {

        var eventObject = {
            'eventCategory' : eventCategory,
            'eventAction' : eventAction,
            'optionalEventLabel' : optionalEventLabel,
            'optionalEventValue' : optionalEventValue,
            'page' : pageName,
        };

        console.log("app.trackEvent - " + JSON.stringify(eventObject));

        ga('send', 'event', eventObject);
    }
}

I call this method from many places using a call like:

app.trackEvent("PageNameValue", "EventCategoryValue", "EventActionValue", "EventLabelValueIfIHaveOne", AnIntegerValueIfIHaveOne);

Any help or suggestions will be greatly appreciated.

Edit... I found the following bug report that seems to apply: https://code.google.com/p/analytics-issues/issues/detail?id=366 The bug reporter mentions solving this problem by setting up a custom dimension. I will give that a try.

like image 792
Diff Avatar asked Apr 08 '16 19:04

Diff


People also ask

How do I know if Google Analytics event tracking is working?

To see if Google Analytics is firing on your page, go to any page on your site in your Chrome Browser and right-click. Click on Inspect. Then go to the Network tab. Hit refresh on your browser and watch to see the different content and scripts loading on the page.


2 Answers

As per google

Since the appName field must be sent with all app hits, it's often best to set that field on the tracker itself using the set command or, alternatively, when the tracker is created:

ga('create', 'UA-XXXXX-Y', 'auto', {
  'appName': 'myAppName'
});

// The `appName` field is now set on the tracker, so
// screenview hits don't need to include it.
ga('send', 'screenview', {appVersion: '1.2'});

// Sending multiple parameters

ga('send', 'screenview', {appName: 'com.company.app', appVersion: '1.2'});

More information here

like image 179
Chetan Sharma Avatar answered Sep 28 '22 00:09

Chetan Sharma


It works if you set at least the "appName", it's a good practice to set "appName" and "appId" before to set "appVersion"

ga('set', 'appId', app.id);
ga('set', 'appName', app.id);
ga('set', 'appVersion', app.version);
like image 27
Vinicius Patrinhani Avatar answered Sep 27 '22 22:09

Vinicius Patrinhani