How to Add Google Analytics User ID Tracking to Your Shopify Store

New Member
1 0 1

If you're setting up a Google Analytics view to capture User ID data, you may be wondering what you need to do to actually capture that data, since Shopify only allows you to enter your Analytics ID. Turns out, it's actually pretty simple. 

After you've gone through the User ID setup, just add the following line to the Additional Google Analytics Javascript section.

ga('set', '&uid', __st["cid"]);

Note: Using Google Tag Manager (GTM) is not required. This will also work with Enhanced Ecommerce.

1 Like
Highlighted

Correct, that's currently the best approach.

Run Google Shopping ads? Get the free definitive guide to Google Shopping for Shopify (no optin required): https://www.digitaldarts.com.au/google-shopping
1 Like
Shopify Partner
5 0 0

@jmings thanks for the tip! I am not sure how your code snippet works exactly though and have a couple of questions:

What does the __st["cid"] variable represent? Is that set by Shopify automatically to represent the current user session? Is that reliable accross devices/browsers? I had the feeling I would have to activate user accounts in Shopify to have a reliable id for each user on my online store.

Will the __st["cid"] also work if user accounts are disabled? Where can I find more info about the __st variable? Thanks!

0 Likes
Shopify Partner
5 0 0

The implementation with __st["cid"]. Does not seem to work with enhanced ecommerce tracking turned on. This is documented in the comments of this blogpost, and  `__st["cid"]` returns `undefined`.

Any idea how to make these working together?

0 Likes
New Member
1 0 0

None of the above worked for me. I have Enhanced ecommerce enabled.

 

This is what works for me (added to the "Additional Google Analytics Javascript") field:

ga('set', 'userId', "cid");

This is exactly what Google suggests in the UserID setup process, but the obviously their {{USER_ID}} example is changed to userId, as seen above.

0 Likes
New Member
1 0 0

Hi,

As per Joshua guide, for tracking logged in users. I used this code :

if(__st["cid"]) ga('set', '&uid', __st["cid"]);

I was able to see User IDs for logged in users in another view but I am not able to get enhanced ecommerce data. However, I am able to see enhance ecommerce data in my Default view.

I have enabled enhanced eccommerce settings. Is this a known issue at shopfiy end or does it need code customization?

Thanks, Arif

0 Likes
New Member
8 0 0

If I've set up userId to be the value of a persistent cookie, will that be accurately reflected with: ga('set', 'userId', "cid");?

Like how is "cid" (customer id?) set?

Thanks,

R

0 Likes

Arif, enhanced ecommerce data will come through. Is it coming through in another view? That is a simple diagnostic. If it is, then the issue is simply not enabling EE on your User ID view.

Renaud, if you see the code snippet in the post above yours, that is how the "cid" value is set. For more help, see my GA guide for Shopify.

Run Google Shopping ads? Get the free definitive guide to Google Shopping for Shopify (no optin required): https://www.digitaldarts.com.au/google-shopping
0 Likes
New Member
1 0 0

step#1 open your Shopify ecommerce dashboard/admin, and then clickOnline Store and then click Preferences.

 

Step#2: Now paste the analytics tracking code in the Google Analytics account field.

Step#3: Click Save and Done!

If you want to see more detailed ecommerce tracking, first enable enhanced ecommerce setting from Analytics as explained in topic 5 below.

Next, from the Shopify admin click Online Store >> Preferences and in the google analytics account field, check the use enhanced ecommerce checkbox.

 

Regards,

Ethan Root

TechTIQ Solutions

Ethan Root_https://www.techtiq.co.uk
0 Likes
New Member
8 0 0

Hey Josh,

Thanks for replying to this thread.

I was able to figure out how to get userId working with cid as your guide laid out.

However, I have a lingering question: if I used GTM to set userId based on first-party cookies, how does setting userId = cid in the checkout get reconciled?

Looking at the console, it does not appear as if those values match up (why would it?). So will we effectively be seeing a pair of different userId values for each user journey in GA?

Thanks,

R

0 Likes