How do I set appVersion for Google Analytics Event tracking

This appears to be be a Google Analytics bug. See https://code.google.com/p/analytics-issues/issues/detail?id=366 for more information.

As suggested by the bug reporter, the workaround is to use a custom dimension that you define in the Admin / Custom Definitions / Custom Dimensions section of the Google Analytics console.

  1. Click "New Custom Dimension"
  2. Enter name ( I entered customAppVersion )
  3. Choose scope ( I chose Hit )
  4. Click Create

Google will then suggest code examples for you, like...

var dimensionValue = 'SOME_DIMENSION_VALUE';
ga('set', 'dimension1', dimensionValue);

The only thing in the code sample that you need to change is the value of 'dimensionValue'. So I ended up with the following code.

ga('create', 'UA-########-#', 'auto');
ga('set', 'checkProtocolTask', null); // Disable file protocol checking (so that GA will work on Android devices)
ga('set', 'dimension1', app.version);
ga('send', 'pageview');

After this, the custom dimension will be applied to each hit recorded by Google Analytics and you can use that custom dimension to filter your results in the Google Analytics console.


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);

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