escopecz / grav-ganalytics

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

JavaScript functions to enable/dissable tracking #24

Open rluetke opened 4 years ago

rluetke commented 4 years ago

I have added the JavaScript functions setGaTracking(on) and getGaTracking(), which can be used as callback functions in an cookie consent dialog.
The following code sample allows users to activate or deactivate tracking using a checkbox:

<label><input type=checkbox id="gaCheckbox" name="gaCheckbox" value="1" onClick="changeGaTracking()"> Google Analytics Tracking.</label> 
<script>
var checkBox = document.getElementById("gaCheckbox");
checkBox.checked = getGaTracking(); // show tracking status
function changeGaTracking() {
  setGaTracking(checkBox.checked); // change tracking status
}
</script>

This becomes neccessary as the Europe’s top court says active consent is needed for tracking cookies. As next task I try to use these functions as callbacks in https://github.com/naucon/grav-plugin-cookieconsent (or equivalent). The cookie consent must allow the user to activate or deactivate tracking.

Furthermore I changed the plugin version to 1.5 and added the last commits to the CHANGELOG.md.

Regards, Ralf

rluetke commented 4 years ago

Hi John,

meanwhile I extended the grav-plugin-cookieconsent to allow/deny cookies and added a callback function to enable/disable cookies/tracking.
See pull request 11: https://github.com/naucon/grav-plugin-cookieconsent/pull/11

In this pull request I also described the usage under https://blog.dmr-solutions.com/. It's working :-)

cookieconsent and ganalytics are working together:

Regards, Ralf

rluetke commented 4 years ago

Hi John @escopecz ,

today I added the possibility to opt in tracking by an external cookie set by a cookie consent plugin.

After new European jurisprudence the tracking may take place only after the user has agreed (= opt in). Consequently, the first page view must not be tracked. This can be achieved by inserting the tracking code only if tracking has been allowed. The tracking code must therefore wait for the consent cookie.

To achieve this I added a blocking cookie value to explicitly allow tracking. You can see this working under https://blog.dmr-solutions.com/ together with https://github.com/naucon/grav-plugin-cookieconsent/pull/11:

I described it in detail in the README.

Please accept the pull request and merge it into your master. Then the new plugin version will be 1.5. Pleople are waiting to follow the new tracking jurisprudence.

Regards, Ralf

ViliusS commented 1 year ago

A lot have changed for the past few years. Google have migrated to GA4 and the new Consent Mode was introduced.

Moving forward I think it would be great to have functionality in this PR, but modernized, maybe using Consent Mode. What do you think @rluetke ?

rluetke commented 1 year ago

Hi Vilius,

thank you for your question und sorry for my late answer, too much work!

The new Consent Mode is a nice idea if you trust google.

I prefer not to send any data to Google at all unless the user has explicitly agreed to it.

This is possible by https://github.com/naucon/grav-plugin-cookieconsent together with https://github.com/escopecz/grav-ganalytics.

But I would like to simplify this and put it into one plugin if I had time. …

Regards, Ralf

Von: Vilius Šumskas @.> Gesendet: Samstag, 10. Juni 2023 16:05 An: escopecz/grav-ganalytics @.> Cc: Ralf Lütke @.>; Mention @.> Betreff: Re: [escopecz/grav-ganalytics] JavaScript functions to enable/dissable tracking (#24)

A lot have changed for the past few years. Google have migrated to GA4 and the new Consent Mode https://support.google.com/analytics/answer/9976101?hl=en was introduced.

Moving forward I think it would be great to have functionality in this PR, but modernized, maybe using Consent Mode. What do you think @rluetke https://github.com/rluetke ?

— Reply to this email directly, view it on GitHub https://github.com/escopecz/grav-ganalytics/pull/24#issuecomment-1585678939 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPXJ73D4GNR257KIBJMZF3XKR5IRANCNFSM4I54DJBQ . You are receiving this because you were mentioned. https://github.com/notifications/beacon/ACPXJ7YW7DPEWW5MXRN5DRTXKR5IRA5CNFSM4I54DJB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOL2BYUWY.gif Message ID: @. @.> >

ViliusS commented 1 year ago

The problem with those cookie consent plugins is that they do not differentiate between essential cookies and non-essential cookies, which doesn't allow to track GA page view events without a consent, even if they are anonymous. So, in theory this leaves us with a choice between: a) do not trust Google and have considerably worse analytics (only up to 10% of users give consent to cookies), or b) trust Google more with their Consent Mode and have at least analytics parts right.

Since Grav is used with all kind of websites which do not need Advertisement signals in GA, I would say that b) option would be preferrable.