Capturing User ID in Google Analytics
Received this question from a client. @Adrian we spoke about this briefly. Is there a way to handle this with GA or is there potentially a customization we could do to help them out here?
We’re looking at how we better identify our users. As part of this, I’d like to understand whether it might be possible to capture the Vanilla user ID using our GA tagging on the forum sites. We’d like to use this to link back to the Vanilla user data that Assaf here is currently working on building the incoming data feed for.
We’ve had a look at the logged-in pages, and can’t see that the ID is available. Can you advise whether this is the case, and what value might need to be picked up? Could we easily amend our GA code to enable capture of the ID as a GA custom dimension?
Comments
-
They need to be careful how they implement, but it would be doable. I am on the fence how far we go to tell customers how to do Google Analytics, but they can get the info of the current userid via profile.json - once again though, this is something hacky, which I am not sure how it will be supported in the future officially. You will need to confirm with a dev. Also point them to this, to make sure they know the risks https://developers.google.com/analytics/solutions/crm-integration#user_id
0 -
Is there a way to handle this with GA or is there potentially a customization we could do to help them out here?
- If they had advanced analytics, they could access user info from the
gdn.metaJavaScript variable. - We could create a very simple customization to add user info to the
gdn.metaJavaScript variable. They can pull the user ID, only, from their login cookie and then use that in GA calls. Vanilla uses JWT for login cookies. For users who are signed-in, the "sub" field contains the current user's ID.Nevermind! You cannot access this cookie via JavaScript.- As Adrian mentioned, they could hit the /profile.json endpoint to grab data about the current user. However, this does require a secondary request to the site to gather this information, unlike the other three options.
All that said, are we sure this is something we want to do? It seems like this is maybe opening up the potential to undermine the value of Vanilla's own analytics offering.
2 - If they had advanced analytics, they could access user info from the
-
Aren't our login cookies HTTP-only?
So [3] wouldn't work?
0 -
Pretty sure I did a customization for chip at some point to make some specific data available in javascript for their custom analytics provider. From a business perspective 🤷♂️.
Technically we already have the user data in a few places in javascript, but not in any official capacity that is unlikely to change in their near future.
0 -
All that said, are we sure this is something we want to do? It seems like this is maybe opening up the potential to undermine the value of Vanilla's own analytics offering.
This is kind of where my own concern is, in terms of us pointing out to them how to implement Google Analytics. We can certainly point to them the data is available. What they do with it, we should not comment further, beyond pointing to GA documentation. They can easily run afoul of Google's TOS with regards to PII and we don't want to be held accountable for their mistakes.
0 -
Our analytics do not know anything about the users in the rest of the client’s web presence. Conversely, they can implement GA everywhere to get a more holistic view. I’m pretty certain that’s where all these types of requests come from.
0 -
Absolutely, the request is fair. I am saying we should be drawing the line at offering the how-to on the GA implementation aspect. It places us at the heart of any issue that comes from them doing it wrong.
0 -
I have no issue helping them add UserID to the
gdn.metaarray and passing that to GA. I suggest it as a small customization.0 -
I should be clear, I was not suggesting we don't help them or share the info they need. I just wanted to point out it's on them to do the GA work once they have the info they need. I think consulting on best GA practices is outside our scope.
0 -
For sure. I was replying to Ryan's business concern.
Our work is definitely limited to making it available.
0 -
In option 1, why do they need advanced analytics? Also, if someone has time I'd like a quick walk through of this.
0 -
In option 1, why do they need advanced analytics?
Because we add extended user info to the page as part of advanced analytics. It isn't there by default.
1 -
Just to come full circle the code for this would be (assuming they use Gtag)
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-561164-24"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-XXXXXX-XX', { 'user_id': gdn.meta.eventData.user.userID.toString() }); </script>Following info here: https://support.google.com/analytics/answer/3123666?hl=en
Thanks to @slafleche for the assistance.
0
