jehna / ga-lite

Small, cacheable and open version of Google Analytics JS client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alternative async tracking snippet

p0358 opened this issue · comments

commented

How about adding something like "Alternative async tracking snippet" from https://developers.google.com/analytics/devguides/collection/analyticsjs/ to docs?

I believe it could look something like this:

<script>
window.galite=window.galite||function(){(galite.q=galite.q||[]).push(arguments)};
galite('create', 'UA-XXXXX-Y', 'auto');
galite('send', 'pageview');
</script>
<script async src="https://cdn.jsdelivr.net/npm/ga-lite@2/dist/ga-lite.min.js"></script>

(caution: didn't test this)
Also, why doesn't it save the time on creating the placeholder galite fucntion? Does it not report page load time?

Sounds good, this could be a part of the README.

No, ga-lite does not currently report page load times. Opened issue #46 for that.

This alternative syncing code is working for me.

Is there a particular reason why it hasn't been added to the README in the last months? I don't know enough JavaScript to know whether this is a good approach for production or not. I'd rather not use something that's 'frowned upon'. 😄

The reason is only that the loading script is subject to small changes when #46 is implemented, so I haven't added it in yet 😄

The script from @p0358 translates directly to the current script found in readme, so it's perfectly safe to use.

Thanks for your quick reply. Good to know this code approach is good to use.

(Also thanks for your work on the ga-lite project as a whole. It's pretty amazing. 😄 )