Everything man, I cannot receive events on Google Analytics despite the analytics.js appearing on Network tab (Ctrl+Shift+I). I tried:
1 - Creating putting the gtag async script in the header part of the HTML file within Playcanvas
2 - Loading the analytics.js directly form google using the external scripts link in the setting menu
3 - Extracting the raw analytics js from google and importing into playcanvas so it loads when the experience loads
May someone please provide the steps one has taken in order for it work? Maybe have a sample project? THis is something that would be very useful for users and the developer community.
I tried following both approaches in this thread but couldn’t get anything to work.
I created a property in my google analytics account. Set a name, set the default url (points to launch.playcanvas.com/projectId), set the industry category, clicked save.
I forked yaustar’s project in order to test it. replaced the code in ga.js with my property’s tracking id and hoped a pageview hit would show up. But it doesn’t.
From the dev tools console I can tell that the “ga” object is not defined. Copy pasting the code into the console creates the ga object and corresponding script tag which loads analytics.js.
After that I can issue the calls to ga without any errors. However no hits show up.
I tried setting up gtag as well based on Travis’s explanation too, but nothing happens that way either.
The 1 user in the middle of the graph is you. The two right now on the right are me in 2 seperate google chrome tabs. The fact that they are chrome tabs is very important. My default browser is Brave… guess what is blocked by Brave … the browser which advertises specifically with privacy … of course! Google Analytics does track Brave.
The only weird part is that I don’t even see my console.log() before ga(‘create’ in brave. The entire file is blocked.
Thanks for helping and sorry for wasting your time
Hi, I am trying to do the same thing you did here and am having trouble with the last sentence you stated. How do I make a gtag call somewhere in my project where it will be activated? Previously in JS, I have used import/export to call functions outside of their own script but I understand this doesn’t work in PlayCanvas as it is an ES6 feature. How/where did you make your gtag call?
Hi, this is the method I used and it works great! (Referring to the gtag method in case it isn’t clear in this thread) But can you elaborate on what you mean by “gtag call to any useful spot in my project”? I’d like to create some kind of event during a particular button-push but I can’t figure out how to implement this. Thanks!
Hi, I think I figured it out. Isn’t it awesome when you can answer your own question a minute after you’ve posted it for the world to see? I added an event using this:
which registers as an “urlClick” in google analytics.