10

I've turned on User ID tracking, and am using the following code:

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '<UA-ID>');

//gtag('config', '<UA-ID>', {'user_id': '{% user_display request.user %}'});

// https://developers.google.com/analytics/devguides/collection/gtagjs/setting-values
gtag('set', {'user_id': '{% user_display request.user %}'}); // Set the user ID using signed-in user_id.

I've confirmed that the user_id value is being properly set by the JS. Also, I am able to see tracking info, except that it is NOT attached to a user.

Wondering if anyone has set this up before and could help debug. Also, note that I am using GTAG not the older Analytics (which I believe is called UA - Universal Analytics).

10

I figured this out, User ID has to be set before the pageview event is sent. Maybe just after the function gtag() declaration would help.

I switched over to the older analytics.js since it is much better supported. The same applies there as well.

| improve this answer | |
  • 1
    Exactly, GA's User-ID documentation is bad when saying "add" but not "insert" this line before gtag('config'...); – Tien Do Dec 13 '17 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.