auth0 / auth0-analytics.js

Auth0 Analytics (Web)
https://auth0.com/docs/analytics/integrations
MIT License
4 stars 6 forks source link

Can't get working on hosted page #18

Open mattwhetton opened 6 years ago

mattwhetton commented 6 years ago

I've been trying all morning to get google analytics working with this on a hosted login page on a custom domain but I just cant see any events making it through.

I've tried both the google analytics and google tag manager configurations, but neither is raising any events.

All I've done is pretty much added these lines:

<script>
    window.auth0AnalyticsOptions = {
      'google-analytics': {
         id: params.googleTrackingCode
      }
    };
</script>

<script src="https://cdn.auth0.com/js/lock/11.6.1/lock.min.js"></script>
<script src="https://cdn.auth0.com/js/analytics/1.3.1/analytics.min.js"></script>`

Am I missing something?

mattwhetton commented 6 years ago

I've kind of got to the bottom if my issue.

The first problem is that I had to enable cross domain tracking for the property, which I didn't realise I had to do! Totally makes sense though!

Second problem was that I couldn't get the script auto-loading feature to work - not sure why, but I cannot get that working. So I switched to manually preloading.

Third problem, the script is using the legacy ga code to log events to google analytics. I was preloading using the gtag (not tag manager) tracking code. Took me a while to work out the difference between ga, gtag and full google tage manager, but now I think I get it!

So I'm now preloading the legacy ga code and it looks to be working.

I also did try using the google-tag-manager tracker with gtag, but that also didn't work. I think that the datalayer methods dont log immediately to google analytics (maybe you choose them in tag manager). The gtag syntax for logging to analytics is a little different

If I get time, I'll try to write a gtag supporting tracker and submit a PR

adamlofts commented 5 years ago

@mattwhetton I am having the same issue. Could you explain how to enable cross domain tracking on a property?

avernikoz commented 5 years ago

I've just did the steps that has official tutorial and it works fine. Just add this code to your head in provided order: `

<script src="https://cdn.auth0.com/js/analytics/1.3.1/analytics.min.js"></script>`

Without any set up something else in GA.

adamlofts commented 5 years ago

@avernikoz You are correct. My problem was that I stripped the UA- prefix of my GA ID.

If you have a chance I would suggest updating your docs, they currently look like this:

image

change id: 'YOUR_GA_ID',

to id: 'UA-XXXXXXXXX-X',

This will help stop people like myself making silly mistakes.