Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Opt Out Option #488

Closed
sprankhub opened this issue Feb 10, 2017 · 7 comments

Comments

3 participants
@sprankhub
Copy link

commented Feb 10, 2017

It is possible to disable tracking via

window['ga-disable-UA-XXXXX-Y'] = true;

See https://developers.google.com/analytics/devguides/collection/analyticsjs/user-opt-out#opt-out_of_tracking_for_your_site. For the old ga.js script, there was an official code suggestion by Google in order to implement such an opt out (see https://developers.google.com/analytics/devguides/collection/gajs/):

<script>
// Set to the same value as the web property used on the site
var gaProperty = 'UA-XXXX-Y';

// Disable tracking if the opt-out cookie exists.
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
  window[disableStr] = true;
}

// Opt-out function
function gaOptout() {
  document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
  window[disableStr] = true;
}
</script>

This should work with the new analytics.js script as well.

Could you either provide an option, which enters the above code above all other JS code inserted by this plugin or at least provide an option to insert some code in the backend, which will be inserted before all other code? The "invidiual code" field does not work in this case as the code is inserted too late.

Thanks!

@chriscct7

This comment has been minimized.

Copy link
Member

commented Feb 19, 2017

Hi there,
It's on our lists of things to do :-)

@chriscct7

This comment has been minimized.

Copy link
Member

commented Mar 13, 2017

This feature is shipping with our next release.

Please note, as the ga.js tracking version of MonsterInsights is deprecated, we are no longer adding new features to it.

Therefore, to use this and other features, you must switch to Analytics.js if you have not already. If you are a new user, or if you are an existing user who does not see a notice to switch to Analytics.js on the General tab of the MonsterInsights settings panel, you are using Analytics.js (universal tracking).

To reduce conflicts with other plugins as well as to follow our plugin standard JS, our prefixed version of the function for the optout is __gaTrackerOptout. You can also check to see if a user is opted out using __gaTrackerIsOptedOut

An example optout link is as follows:
<a href="javascript:__gaTrackerOptout()">Click here to opt-out of Google Analytics</a>.

@chriscct7

This comment has been minimized.

Copy link
Member

commented Mar 13, 2017

Closing issue. This will ship with our next major release (6.1).

@chriscct7 chriscct7 closed this Mar 13, 2017

@sprankhub

This comment has been minimized.

Copy link
Author

commented Mar 13, 2017

Awesome, thanks @chriscct7!

@chriscct7 chriscct7 added this to the 6.1 milestone Mar 13, 2017

@chriscct7

This comment has been minimized.

Copy link
Member

commented Mar 13, 2017

Not a problem!

@chriscct7

This comment has been minimized.

Copy link
Member

commented Aug 30, 2017

As an update this plugin is also compatible with MI: https://goo.gl/9YruJA

@aaart42

This comment has been minimized.

Copy link

commented Nov 8, 2017

Thanks a lot for this feature!

I just implemented __gaTrackerOptout() on my site. However I'encountered that this function throws an exception when executed as an admin.

This is obvious, because I've excluded the admin role from being tracked by MI. Thus the function does not exist, when I'm logged in as admin. Nevertheless the exception could be caught somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.