This message was deleted.
# questions
b
This message was deleted.
e
Hey @sticky-night-20812, we don’t have any documentation on Google Analytics 4 yet, but we can write one. Are you looking to find anything specific?
s
Basically the recommendation about how to setup things properly. For instance, I’m not sure if the custom JS should be in the “per-page script” or “one-time script” section. How to define the user ID, user properties, etc. I figured some of those myself, but having official guidelines would definitely help.
e
Gotcha, thanks. Looking at what we have now in the backend, we usually just ask for the ID and then insert these scripts with IDs replaced. To be run once
Copy code
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="<https://www.googletagmanager.com/gtag/js?id=UA-XXX>"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXX');
</script>
To be run per page change
Copy code
<script>
	function getUserid(){
	    try {
	        var studioUser = localStorage.getItem('studio_user');
	        if(studioUser) return;
	        var user = JSON.parse(localStorage.getItem('user'));
	        var sid = user._sid;
	        var recIndex = sid.indexOf("rec");
	        var recId;
	        if (recIndex >= 0) {
	            recId = sid.substr(recIndex);
	        }
	        return recId;
	
	    } catch (e) {
	    }
	}
	
	var userId = getUserid();
	var config = {
	'page_path': window.location.pathname
	};
	
	if(userId){
	    gtag('set', {'user_id': userId})
	}
	
	gtag('config', 'UA-XXX', config);
</script>
👍 1
I’ll put the GA script article on my todo list
g
@elegant-eve-85294, what user id is defined above?
Actually, just checked in console and found it. I’m wondering, isn’t it against GA4 Terms to use identifiable user_id values?
Also, the example above is for using “GA4” through GTM, right? What about using GA4 directly, are there any disadvantages in that?
e
Hey @gifted-leather-56422, I do not have much knowledge about Google Analytics at this stage. We do not have an official Google Analytics integration, so what we’ve been using is the best we know how to make it work for most folks. Having said that, whenever customers come with a specific script they want to insert, we insert that instead. If you can supply us with a valid GA4 script, we would be happy to insert it in your workspace. Could you point me to the relevant section in GA4 Terms? If we’re doing something we shouldn’t be, we’ll be happy to amend the script we use for customers who don’t give us anything. I do not know about any disadvantages of using GA4 directly, but more experienced Google Analytics folks in this Slack might know more.
s
@gifted-leather-56422 It’s not GTM, it’s GA4 directly. I don’t know about the rules of using GA4, anyway, if you track things you shouldn’t, you’re the one responsible (not Stacker, not GA). Using the user ID shouldn’t be an issue, I’m not 100% sure, though.
g
https://developers.google.com/analytics/devguides/collection/ga4/user-id?technology=gtagjs#generate_user_ids
This includes avoiding the use of impermissible personally identifiable information, and providing appropriate notice of your use of identifiers in your Privacy Policy. Your user ID must not contain information that a third party could use to determine a user's identity.
👍 1
s
Yeah, they’re basically protecting themselves to avoid GDPR concerns. I still think it’s fine to use the Airtable ID, because only Airtable and Stacker would be able to “determine a user’s identity” based on it, and no matter what other information you would use as GA ID, Airtable and Stacker would still be able to determine to which user it relates to. So, I guess what’s really important is that no other 3rd party should be able to identify a user’s identity based on an Airtable ID. So, as long as the user ID isn’t made public, this shouldn’t be an issue. If you want to avoid any concern, you’ll need to build your own ID generator, but I doubt that’s simple considering Airtable doesn’t offer any built-in crypto function.
g
Oh, that’s a good point, I just looked at the code again, and seems like it passes the ID of the row form Airtable, so I think that should be a good enough protection of PII!
s
Yeah, it’s something like
rec_abc123
which cannot simply be translated into an identifiable information like an email or name.
@elegant-eve-85294 So, the script above is fine IMHO, it doesn’t violate the GA rules. Although, I’m not sure why you manually specify
page_path: window.location.pathname
for GA4, as far as I understand, it should be automatically done by GA. Did you run into any issue?
👍 1
e
I think it might be a bit of legacy code @sticky-night-20812, the script I shared was here before I joined Stacker. I can’t find it being a problem in our internal conversations
s
I think it was valid for GA3, but unecessary for GA4, since GA4 natively supports SPA.
🙇 1
g
@elegant-eve-85294, would you keep this script for longer? For some reason I thought that these “rec….” values were just random ids from GA4, but now as you showed this code snippet, and I also see this snippet in our instance, it looks like a real record ID, which is amazing. So just want to make sure this won’t get removed
s
The “rec” is from airtable, and it won’t get removed unless they want to break thousands of apps and API integrations
➕ 1
g
What I had in mind is the getUser() function to grab that value and pass through to GA