Skip to content

Add Custom hitCallback Functionality#13

Open
timdmackey wants to merge 1 commit into
escopecz:masterfrom
timdmackey:master
Open

Add Custom hitCallback Functionality#13
timdmackey wants to merge 1 commit into
escopecz:masterfrom
timdmackey:master

Conversation

@timdmackey

@timdmackey timdmackey commented May 26, 2017

Copy link
Copy Markdown

I added the ability for myself to include a custom hitCallback function in my analytics tracking code, and thought that it might be useful to some other people. This patch adds a new form field to the admin, and if the user has entered their own custom callback function, it will be included on the analytics pageview send.

I also took the liberty of correcting a typo in the "TRACKING_ID" variable name (was “TACKING_ID”). German and Spanish translations are still needed for new parameters in de.yaml / es.yaml, I just put in the English text with a note and hopefully someone can translate it.

As an example of what this functionality is useful for, I use the callback to remove my google utm parameters from the url after the page landing has been tracked, giving the user a much cleaner url to look at and to possibly bookmark:

function() {
  if (window.location.search.indexOf('utm_') != -1 && history.replaceState) {
    history.replaceState({}, '', window.location.toString().replace(/(\&|\?)utm([a-z0-9-_.=+]+)/ig, "").replace(/&/, "?"));
  }
}

screen shot 2017-05-26 at 1 46 27 pm

* Add Custom hitCallback Functionality
(https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits#hitcallback)
* Fix typo in TRACKING_ID variable name (was “TACKING_ID”)
* German and Spanish translations still needed for new parameters in de.yaml / es.yaml
@escopecz

Copy link
Copy Markdown
Owner

Looks good! Thanks! It'd be nice to document that in the README.md too. Do you think you could add the notes about this new option there?

@timdmackey

timdmackey commented Jun 1, 2017 via email

Copy link
Copy Markdown
Author

@escopecz

escopecz commented Jun 1, 2017

Copy link
Copy Markdown
Owner

Just leave those translations in English without any note about needing a translation. When someone speaking the language be willing to translate those, he can create a PR with the change. But the note will make the UX worse until it happens.

Yes, I'm all for it. The smaller and focused the PR the better.

@escopecz

Copy link
Copy Markdown
Owner

This PR needs 2 simple things:

  • Instead of (NEEDS TRANSLATION) in the translation files rather use dump Google Translate version of it. It will result in much better user experience.
  • Add an example use to the readme.

@timdmackey Please let me know whether you will be able to get to it. If not, I will close this PR.

@ViliusS

ViliusS commented Jun 10, 2023

Copy link
Copy Markdown
Collaborator

@timdmackey will you be willing to update this for GA4? This doesn't work at the moment because in GA4 one needs to use event_callbacks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants