0

I'm setting up UserID tracking in Google Analytics. Google's documentation displays this piece of code to push UserIDs into analytics:

ga('create', 'UA-XXXX-Y', { 'userId': 'USER_ID' });
ga('send', 'pageview');

However, when I'm in my Google Analytic's settings area, it displays the following piece of code to include UserIDs.

ga(‘set’, ‘&uid’, {{USER_ID}}); // Set the user ID using signed-in user_id.

What is the difference between set and create? Do they both achieve the same result?

1 Answer 1

1

Both of them should work. Including the user id in the 'create' call includes setting it as well.

ga('create', 'UA-XXXX-Y', {'userId': 'USER_ID'});
ga('send', 'pageview');

is equivalent to

ga('create', 'UA-XXXX-Y');
ga('set', '&uid', {{USER_ID}}); // Set the user ID using signed-in user_id.
ga('send', 'pageview');

If you do copy and paste provided in GA, then you will need to change the smart quotes to straight quotes, because smart quotes will break GA.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.