Skip to content

Instantly share code, notes, and snippets.

@Dan0sz
Created February 10, 2022 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dan0sz/eac6f903c3074ad11ca10dfae8a15fa1 to your computer and use it in GitHub Desktop.
Save Dan0sz/eac6f903c3074ad11ca10dfae8a15fa1 to your computer and use it in GitHub Desktop.
Proxy Google Analytics traffic using sendHitTask
ga('create', 'UA-XXXXXX-Y', 'auto');
// Insert this function after the property is created and before the pageview is sent.
ga(function(tracker) {
tracker.set('sendHitTask', function(model) {
payload = model.get('hitPayload');
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://yourdomain.com/your-proxy-file.php', true);
xhr.send(payload);
});
ga('send', 'pageview');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment