Reputation: 35
We are currently trying to match our users database with information from Google Analytics and we would like to push their user id to GA so we can then retrieve data about our users.
We are currently using this code but it doesn't appear that we can properly get reports with this new user_id custom dimension.
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-xxxxx-1', 'auto');
ga('require', 'displayfeatures');
var dimensionValue = 'xxxxx'; //contains the user id
ga('set', 'user_id', dimensionValue);
ga('send', 'pageview');
</script>
Here is how it's setup on Google Analytics
And here is currently what we can see on Google Analytics
The "74" value is definitely not right and I don't know where it's coming from.
Alternatively we would like to match our user ids with their acquisition source (where they first came from when reaching our website), so I suppose we would need to do something like a "session unification". However the built-in User-Id feature of Google Analytics Universal doesn't seem to allow to retrieve the actual user-id value.
If there is any way we could do this, we are opened to suggestions. If you have experience implementing this or any idea what solution we should look into, it'd be much appreciated.
Thank you.
Upvotes: 1
Views: 233
Reputation: 13495
To set it as a custom dimension you need to use dimension#
rather than the name you gave the dimension in the Analytics account.
For example:
var dimensionValue = 'xxxxx'; //contains the user id
ga('set', 'dimension1', dimensionValue);
As you are setting this for a custom dimension rather than using the UserId feature you don't need to worry about the problem of losing source attribution. (I also use a custom dimension instead of the UserId feature for this reason.)
Upvotes: 1