escopecz / grav-ganalytics

Google Analytics plugin for Grav CMS
MIT License
20 stars 9 forks source link

Add Custom hitCallback Functionality #13

Open timdmackey opened 7 years ago

timdmackey commented 7 years ago

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

escopecz commented 7 years ago

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 commented 7 years ago

Sure, I will try to get to that soon. Do you think someone will be able to translate those couple of lines for me?

Also, I was thinking it might be better if I split out the variable typo correction into a separate pull request to keep things more organized. Thoughts? On Mon, May 29, 2017 at 11:46 PM, John Linhart notifications@github.com wrote:

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?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/escopecz/grav-ganalytics/pull/13#issuecomment-304789095, or mute the thread https://github.com/notifications/unsubscribe-auth/AALJ9H-fVuZvTwNYLfg04UjSaHsFpQfuks5r-7szgaJpZM4NoD9P .

escopecz commented 7 years ago

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 commented 4 years ago

This PR needs 2 simple things:

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

ViliusS commented 1 year ago

@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