Skip to content

JavaScript functions to enable/dissable tracking#24

Open
rluetke wants to merge 4 commits into
escopecz:masterfrom
rluetke:master
Open

JavaScript functions to enable/dissable tracking#24
rluetke wants to merge 4 commits into
escopecz:masterfrom
rluetke:master

Conversation

@rluetke

@rluetke rluetke commented Oct 6, 2019

Copy link
Copy Markdown
Contributor

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

@escopecz escopecz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks great! Just needs to be tested.

@rluetke

rluetke commented Oct 10, 2019

Copy link
Copy Markdown
Contributor Author

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: naucon/grav-plugin-cookieconsent#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:

  • ganalytics provides a JavaScript function to enable/disable Google Analytics and
  • cookieconsent uses this function as a callback, when cookies are allowed or forbidden.

Regards, Ralf

@rluetke

rluetke commented Nov 3, 2019

Copy link
Copy Markdown
Contributor Author

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 naucon/grav-plugin-cookieconsent#11:

  • delete all cookies: no JavaScript tracking code in page
  • allow tracking: JavaScript tracking code in page
  • deny tracking: no JavaScript tracking code in page

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

ViliusS commented Jun 10, 2023

Copy link
Copy Markdown
Collaborator

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

rluetke commented Jul 8, 2023 via email

Copy link
Copy Markdown
Contributor Author

@ViliusS

ViliusS commented Jul 9, 2023

Copy link
Copy Markdown
Collaborator

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants