I am using Angulartics for track some information to Google Analytics from AngularJS.
I need to set a Custom Dimension, I need to do something like this but using Angulartics third party.
ga('set', 'dimension5', 'custom data');
In the documentation of Angulartics I just saw pageTrack()
or eventTrack()
methods. So I don't if it's possible?
Angulartics allows to set Custom Dimensions and Custom Metrics via setUserProperties({'dimension' + index : 'dimension-value'})
. For Metrics you pass an object with the analogous data. The important thing is to use the prefix 'dimension' or 'metric' concatenated with the index of your custom dimension/metric. Indices for free users are [0,19], for premium users [0,199].
Valid examples of setting custom dimensions/metrics are:
$analytics.setUserProperties({'dimension1': 'dimension1-value'});
$analytics.setUserProperties({'dimension2': 'dimension2-value'});
$analytics.setUserProperties({'dimension3': 'dimension3-value'});
...
$analytics.setUserProperties({'metric1': 'metric1-value'});
$analytics.setUserProperties({'metric2': 'metric2-value'});
$analytics.setUserProperties({'metric3': 'metric3-value'});
...
A look into angulartics-google-analytics' source code shows:
$analyticsProvider.registerSetUserProperties(function (properties) {
// add custom dimensions and metrics
setDimensionsAndMetrics(properties);
});
function setDimensionsAndMetrics(properties) {
if (window.ga) {
// add custom dimensions and metrics
for(var idx = 1; idx<=200;idx++) {
if (properties['dimension' +idx.toString()]) {
ga('set', 'dimension' +idx.toString(), properties['dimension' +idx.toString()]);
}
if (properties['metric' +idx.toString()]) {
ga('set', 'metric' +idx.toString(), properties['metric' +idx.toString()]);
}
}
}
}
See Allow setting dimensions/metrics via setUserProperties()
As of version 0.1.2
angulartics.google.analytics
supports setting custom dimensions for both page and event tracking.
You can set custom dimensions like this
$analytics.setUserProperties({dimension1: 'myValue'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With