revolunet / angular-google-analytics

Google Analytics tracking for your AngularJS apps
MIT License
652 stars 172 forks source link

custom dimensions are not working at all #91

Closed Karpo72 closed 9 years ago

Karpo72 commented 9 years ago

Well I don’t receive any custom dimensions. The documentation from google tells me, that dimensions have to be send within a tacked pageView or to be set before the pageView is tracked. My guess ist hat the pageView gets send before the dimensions are set.

I see the commands for the dimens send to the _ga functions, but within chrome debugging I don't see them within the page view tracking. No request to google analytics contains the dimensions.

justinsa commented 9 years ago

@Karpo72 can you provide links to the documentation you read? I would appreciate that so I can make sure I am reading the same thing you are and help resolve this.

Karpo72 commented 9 years ago

@justinsa I just went to this documentation: https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets

justinsa commented 9 years ago

There are two ways to define this using angular-google-analytics and both of those are working in the library, but clearly you must have a scenario that isn't working.

The documentation for GA says that these custom dimensions have to be defined in the GA account before they can be sent. Just double checking that you have already done that?

Also, the rules for when custom dimensions are associated looks fairly specific: https://support.google.com/analytics/answer/2709828. You may want to double check that documentation to see if you are adhering to the requirements.

The GA documentation provides the following example:

// Set value for custom dimension at index 1.
ga('set', 'dimension1', 'easy');

// Send the custom dimension value with a pageview hit.
ga('send', 'pageview', '/level_1/');

But this just states that the first command, 'set', will be applied to the 'pageview' or 'event' command proceeding it.

The alternative method that you should consider is using the optional parameter for the trackPage call in angular-google-analytics, which removes this reliance of association and makes it explicit:

Analytics.trackPage('/video/detail/XXX', 'Video XXX', {dimension15: 'My Custom Dimension', metric18: 8000});

Analytics.trackEvent('video', 'play', 'django.mp4', 4, true, {dimension15: 'My Custom Dimension', metric18: 8000});

Tell me further about what you are seeing and how things are setup so we can try and figure out what is going wrong. Thanks.

Karpo72 commented 9 years ago

@justinsa I will do another test, but I can confirm that I created the dimensions within the GA Account. I'm currently using the ga('set'...) method. Within debugger I see how the dimensions get set, but I don't see them within the GET Requests the script is executing. I set some of them on a very early state -> i.e. within the app.config. If i debug the module I can see that my dimension1 gets set, after that the pageview is called and than the other dimensions are set. I'll do a try with ignoreFirstPageLoad= true and track the first page manually. But I'm wondering that even the first dimension before the inital pageview isn't within the request to GA. Might it be that the set Command is not supposed to use multiple trackers? I couldn't find any information, if this command has also to use the tracker name.

Karpo72 commented 9 years ago

@justinsa I couldn't find any offical description on google, But I found this discussion on stackoverflow with another topic: http://stackoverflow.com/questions/23815965/universal-analytics-custom-dimensions-with-multiple-trackers-old-tracker-recor

Do you see the code of the guy? He also uses the set command with multiple trackers. I#ll do now a test and will disable one tracker, just tos see if the dimensions will be send

Karpo72 commented 9 years ago

@justinsa @revolunet I figgured out the solution. The reason on my site are the multiple tracker. I use the set method. I debugged through the set function and executed the command manually from my console -> _ga('tracker.set', name, value); -> and now see that the dimension get's submitted to GA.

Final I can confirm in my case two problems:

The request to GA should contain CD1 if Dimension1 is set

justinsa commented 9 years ago

That makes sense. Thanks for figuring this out. I think we should take a different tact for this method as we need its current behaviors to be maintained and set is frequently a scenario that is specific to a tracker or the generic case. It doesn't make sense to have it support multi-tracker in the same way as the other methods.

The current method looks like this:

        this._set = function (name, value) {
          _analyticsJs(function () {
            _ga('set', name, value);
          });
        };

I propose we do the following:

        this._set = function (name, value, trackerName) {
          _analyticsJs(function () {
            _ga(getCommandName(trackerName, 'set'), name, value);
          });
        };

This will maintain backwards compatibility but require you to call the same set with different trackers that you want to set custom values for. Thoughts?

Karpo72 commented 9 years ago

@justinsa @revolunet That should work.

Karpo72 commented 9 years ago

@justinsa Did you implement the change for the send command (multiple tracker) already?

justinsa commented 9 years ago

This is in as of yesterday. It was merged in with #100, but I forgot to mark the PR with this issue. I want to get offline mode in and then create a new release. The next release is not backwards compatible, so you are aware. The documentation provides guidance and I would appreciate feedback on it for how it can be improved.