jehna / ga-lite

Small, cacheable and open version of Google Analytics JS client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Customizable endpoint URL and User Language

kidonng opened this issue · comments

commented

I noticed some parameters are hard-coded, specifically, the Google Analytics endpoint URL (https://www.google-analytics.com/collect) and User Language (ul):

'https://www.google-analytics.com/collect' +
'?v=1' +
'&ul=en-us' +

It would be awesome to be able to:

  • Make ul use actual language provided by the user agent (e.g. navigator.language)
  • Use a custom endpoint URL to avoid people blocking the official endpoint

Thank you for opening the issue. Good catch on the ul parameter! This should now be fixeed with #462

Using a custom endpoint would make sense — it would allow for routing the requests from your own domain (getting around any third-party restrictions), and even creating an alternative backends for the ga protocol.

How would you like to pass the endpoint url to ga-lite? How about something like:

galite('create', 'UA-XXXXXXXX-X', 'auto');
galite('set-endpoint', '/my-custom-collect-endpoint');
galite('send', 'pageview');

This would be majorly useful. Looking at using this script to proxy traffic through a cloudflare worker.