How to create an Opt-Out link for Google Analytics (2023)

Privacy is more and more important to visitors and especially in Europe, privacy laws are very strict. Did you know that you even have to offer a link to allow your visitors to opt out from Google Analytics tracking directly on your site? So, in this post I am going to show you how to implement and use such a link.

Opt-Out methods described in this article

  • opt-out methods for visitors
  • code in theme/php files
  • code in WordPress (functions.php + hook)
  • code when using Google Analytics for WordPress plugin by Yoast
  • WordPress plugin without coding

How visitors can opt-out from Analytics

The easiest solution to not send your visitors data to Analytics is simply by not using it on your site. But, of course, that is not the solution I am going to discuss here. This leaves solutions either on the visitors or the webmasters end.

Opting-out using a browser-plugin

The solution to opt-out from Analytics as a visitor is offered by Google itself in form of a browser plugin. You only have to activate it in order to not get tracked on any site using Google Analytics. You find it here.

Also a lot of AdBlockers or other browser plugins might have this feature included.

However, this can not serve as a general solution, because some browsers are not compatible with such a plugin, especially those on mobile devices.

Opting-out on a specific site

The second solution is in the hands of the webmaster, who has to offer a link to opt out from Analytics on his site. As far as I found information on this topic, it is enough to offer such a link in your privacy policy, so tracking visitors when they come for the first time seems inevitable. I am not a lawyer and found very different arguments for very different (European) countries on this matter, so please leave a comment in case you know something specific.

(Video) How to Exclude IP Addresses in Google Analytics Guide | Google Analytics Opt-Out Browser Extension

For now, I will concentrate on the solution on how to offer this opt out link and how to implement it on your site. My tutorial is written for WordPress, but you can probably use a lot from it for other cms as well.

Add an opt-out-link to your privacy policy

Privacy Policy?

The correct place for an opt-out link is the privacy policy of your site. I still see many sites without one, but as far as I know, most countries bound you to have one. Your privacy policy page needs to be accessable from every page, so best include the link into your footer or sidebar navigation.

There are plenty of tutorials and services to create a propper privacy policy. For small sites and the basic features they are also for free or ask for a backlink.

Opt-Out Text

When you are using Analytics and have a proper privacy policy you will already inform your visitors about it. So there is only a short sentence to add to also inform visitors about the opt-out link. It can look like the following.

You can opt-out from Analytics tracking by clicking on this link: (Link).

I am open for a better wording, so please feel free to suggest something in the comments below.

(Video) GA4 Tip 18 - How to opt out of automatic GA4 property set up in GA Universal Analytics

Opt-Out Link

You can take the script for the opt-out link directly from the example on the Analytics developer forum.

<a href="javascript:gaOptout()">Click here to opt-out of Google Analytics</a>Code language: HTML, XML (xml)

Make sure to edit your page in the text editor and not the visual editor so the html code is working.

Opt-Out Script

The function that is called with the Analytics opt-out link does currently not exist. You need to insert it into your website’s code before the actual Analytics code. This is very often the header, but can also be in the footer.

The base code and how to implement it into your theme files

The basic code for the opt out looks like this:

<script>// Set to the same value as the web property used on the sitevar 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 functionfunction gaOptout() { document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/'; window[disableStr] = true;}</script>Code language: HTML, XML (xml)

To make it work you need to change the ua code in the third line into the one from your Google Analytics account.

The code will simply create a cookie that expires in 2100, so it practically works forever or until the visitor cleans the cookies in his browser.

(Video) Google Analytics Opt Out - Don't Hurt Your SEO! - Don Crowther

If you implemented the Analytics code into your WordPress theme, you need to find the file where you put it first. Then simply copy the code from above and put it above the Analytics code. Don’t forget to change the UA code to the one from your Analytics account.

Implementing the code in WordPress’ functions.php

If you inserted the Analytics code in WordPress with the help of a plugin you can put the following code into the functions.php file of your theme (if you use Google Analytics by Yoast see the following section).

add_action( 'wp_head', 'my_opt_out', 1 );function my_opt_out(){?><script>var gaProperty = 'UA-XXX-X';var disableStr = 'ga-disable-' + gaProperty;if (document.cookie.indexOf(disableStr + '=true') > -1) {window[disableStr] = true;}function gaOptout() {document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';window[disableStr] = true;}</script><?php}Code language: JavaScript (javascript)

This code will put the code into your header. Don’t forget to insert the correct UA code.

Opt-Out code with Google Analytics for WordPress by Yoast plugin

If you are using the Google Analytics for WordPress plugin by Yoast, you can even get the UA code from it. This is especially helpful when you run a multisite and every single site has its own tracking code. Simply include the following code into the functions.php file of your theme.

add_action( 'wp_head', 'wg_opt_out', 5 );function wg_opt_out(){ if ( ! class_exists( 'Yoast_GA_Options' ) ) return; $yoast_ga_options = Yoast_GA_Options::instance(); $code = $yoast_ga_options->get_tracking_code(); ?><script> var gaProperty = '<?php echo $code; ?>'; var disableStr = 'ga-disable-' + gaProperty; if (document.cookie.indexOf(disableStr + '=true') > -1) { window[disableStr] = true; } function gaOptout() { document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/'; window[disableStr] = true; } </script><?php}Code language: JavaScript (javascript)

Just a word of caution: after I wrote the first version of this code the Analytics plugin was updated, a global variable I used was gone and my site crashed. This code works, but of course I can’t guarantee for how long.

If you use another Analytics plugin and know how it stores the UA code, you can manipulate the first lines accordingly. Use the third variable in the first line (“5” in my example) to play with the position of the code in case it is inserted below the Analytics code and therefore doesn’t work.

(Video) Google Analytics opt-out | Block yourself from Analytics | Google Analytics opt-out chrome extension

Is there a plugin for that?

For those of you who are not comfortable with hacking their theme files or who don’t have access to them, there is also a very powerful plugin that can help. It is simply called the Google Analytics Opt-Out WordPress Plugin.

The plugin also works with Yoast’s Analytics plugin and – what I like – doesn’t bother users who already clicked on the link.

Testing the code

Testing the Analytics opt-out is rather simple if you know how to check the cookies set in your browser. I am using the web developer toolbar for Firefox, but there are plenty of other ways to check.

Now, simply click on the link you set in your privacy policy and check for a ga-disable cookie like this one:

How to create an Opt-Out link for Google Analytics (1)

You can simply delete it if you want to enable tracking for yourself again.

(Video) What does the Google Analytics Opt-out Browser Add-on do?

Important notes

There are some limitations to the code given, but let me just copy what Analytics has to say about it:

This example code assumes that you are using a single web property on your site and are only using a single domain. It only provides an opt-out function which is based on a long-term cookie. If you require opt-in functionality or if your site uses multiple web properties or domains, you will need to modify this example code, write your own opt-out code, or use other opt-out tools.

The whole topic of data usage and privacy is very complex. However, I hope I was able to help you make your site more complient with local laws. If you feel like I forgot something or you want to add an important note, don’t hesitate leaving a comment below.


How to create an Opt-Out link for Google Analytics? ›

An example opt-out link is as follows: < a href = "javascript:__gaTrackerOptout()" >Click here to opt-out of Google Analytics</ a >. You may paste the above code anywhere you want it, such as a custom HTML widget, page, or post, or even your theme's settings such as in the footer.

How do I allow users to opt out of Google Analytics? ›

How to Let WordPress Users Opt Out of Google Analytics Tracking (In 4 Steps)
  1. Step 1: Install and Activate the Google Analytics Opt-Out Plugin. ...
  2. Step 2: Add Your Tracking Code and Configure the Plugin's Settings. ...
  3. Step 3: Create an Opt-Out Link for Your Website. ...
  4. Step 4: Test If Your Website is Sending Data to Google Analytics.

What is the opt out function of Google Analytics? ›

Tells the Google Analytics JavaScript not to send information to Google Analytics. To provide website visitors the ability to prevent their data from being collected and used by Google Analytics, we have developed the Google Analytics opt-out Browser extension for the Google Analytics JavaScript (ga. js, analytics.

Do you need opt in for Google Analytics? ›

In addition to Google's statement about Advertising Feature usage, you should strongly consider gaining consent in the following situations: Collection of a User ID. Collection of any other pseudonymous identifiers. Collection of detailed geographic data (postal code, latitude/longitude coordinates).

Is it possible to block Google Analytics? ›

If you have a firewall that can block specific IP ranges or domain names, you can block Google Analytics for your entire network. This option also has some downsides, such as IP addresses changing without notice or multiple services using the same IP address.

Is it possible to disable Google Analytics? ›

Sign in using your administrator account (does not end in Google Analytics. Click Service status. To turn a service on or off for everyone in your organization, click On for everyone or Off for everyone, and then click Save.

How do I opt out of data collection? ›

To opt out of data collection, sign out and then sign back in using your web address. The web address is the same URL that you use when you sign in on the web browser.

How do I opt out of Google Analytics 4? ›

In Google Analytics, click Admin. Make sure you are in the correct account and Universal Analytics property. In the Property column, click GA4 Setup Assistant. At the bottom of the page, turn off the Automatically set up a basic Google Analytics 4 property toggle.

Why should I opt data analytics? ›

Data analytics techniques enable a business to take raw data and uncover patterns to extract valuable insights. As a result, data analysis helps companies make informed decisions, create a more effective marketing strategy, improve customer experience, streamline operations, among many other things.

How do I remove my website from Google Analytics? ›

Delete a property
  1. Sign in to Google Analytics..
  2. Click Admin, and navigate to the property you want to delete.
  3. In the PROPERTY column, click Property Settings.
  4. Click Move to Trash Can.
  5. On the confirmation screen, click Move property to Trash Can.

Do I need to own a website to use Google Analytics? ›

You can install and see Google Analytics on any website, and be able to see how many visitors they get. You can also see what pages they went to and how long they spent on your website. You can't see Google Analytics data for another website unless the person who owns the website gives you access, or shows it to you.

Can you use Google Analytics without paying? ›

Google Analytics Pricing Structure

Google Analytics works on the hybrid model meaning it offers the freemium service as well as paid service. The great news is that small business owners can use this service for free without paying any amount or monthly charge.

Is it mandatory to connect every site with Google Analytics? ›

You do really need to have some form of analytics on your website. Without analytics, you can't draw conclusions about how people are using your site. Without data, you can't make the improvements that are going to grow your business or brand.

How do I get access to Google Analytics for my website? ›

Access Analytics via or from your Google Ads account. There are two ways to access Analytics: through a standalone account at, or through your linked Google Ads account. You can sign in to your Analytics account from

How to create Google Analytics account? ›

Create an Analytics account
  1. In Admin, in the Account column, click Create Account.
  2. Provide an account name. Configure the data-sharing settings to control which data you share with Google.
  3. Click Next to add the first property to the account.

Can you share Google Analytics with another user? ›

Google Analytics allows you to grant access to other users so you can share your data with them, or give them more permissions to do things like manage users, edit settings, etc.

How do I create an opt out link in Gmail? ›

Multi-send emails automatically include an unsubscribe link at the bottom of your message so external recipients can opt out of future emails.
  1. On your computer, go to Gmail.
  2. At the top left, click Compose.
  3. From the toolbar at the bottom, click Turn multi-send mode on/off .

What is an unsubscribe link? ›

An unsubscribe link is a link within your email campaign, often placed in the email footer, that allows users to cancel their subscription when they don't want to receive any more emails from you.

Why not to use Google Analytics? ›

It uses cookies so you must obtain consent to store cookies

Google Analytics is a cookie-based web analytics tool and it is not possible to use it without cookies. Google Analytics sets multiple cookies and it “uses cookies to identify unique users across browsing sessions”.

How many people blocking Google Analytics? ›

58% of visitors block Google Analytics

Here's a look at the overall traffic numbers and the difference between Plausible and Google Analytics. Google Analytics is not showing all traffic. It is missing data from 58.67% of all visitors and 58.38% of all page views.

Is it legal to use Google Analytics? ›

Google Analytics transfers the data to US servers and US surveillance laws require US providers like Google or Facebook to provide personal details to US authorities, as required by US law. This violates GDPR and hence is considered illegal by the laws of several countries.

What is opt-out request? ›

An opt out is a request to be removed from an email deployment list for a specific group of messages, or all lists owned by the sender.

What is an example of opt-in and opt-out? ›

Opting out means that someone has to actively take action in order to withdraw their consent for something. For example: If the user does not want to receive any further communication they have to actively tick the above boxes. By doing nothing, they will be opted in.

Why is opt-out better than opt-in? ›

As witnessed in the examples above, opt-in regimes require websites to obtain explicit consent from users. On the other hand, opt-out in cookies are marked consent by default, unless the user rejects the request or withdraws the consent later.

How do I block Google Analytics on Chrome? ›

Turn "Do Not Track" on or off
  1. On your computer, open Chrome.
  2. At the top right, click More. Settings.
  3. Click Privacy and security. Cookies and other site data.
  4. Turn Send a "Do not track" request with your browsing traffic on or off.

Is Google Analytics 4 mandatory? ›

Google Analytics 4 is our next-generation measurement solution, and it's replacing Universal Analytics. On July 1, 2023, standard Universal Analytics properties will stop processing data. We strongly encourage you to make the switch to Google Analytics 4 as soon as possible.

Who should opt for data analyst? ›

If you've studied or worked in a role that involves maths, statistics, computer science, information management, or business information systems, you'll find that you're well-prepared for a career in data analytics.

How did you decide to opt for data analysis? ›

Begin by sharing that you're passionate about data. You can also show your interest by explaining what drew you to the field. For example, you might mention that you enjoy problem-solving and statistical analysis, which led you to a career in data science. When answering, speak sincerely.

How much does the Google data analytics certification cost? ›

The Google Data Analytics Certificate costs $49 per month on Coursera after an initial 7-day free trial period. All Google Career Certificates are completely self-paced. At about 10 hours of study per week, many learners complete a Google Career Certificate in three to six months.

How do I unlink a website from Google? ›

Step 1: Check the Linked accounts page
  1. Go to the Linked accounts page of your Google Account. You might need to sign in.
  2. Select the third-party account you want to unlink from your Google Account. Unlink.

How do I exclude a website from Google index? ›

Add a noindex tag to your page.

A noindex tag only blocks your page from showing up in Google search results. Users and other search engines that don't support noindex can still access your page.

What does Google Analytics do for my website? ›

Google Analytics is a platform that collects data from your websites and apps to create reports that provide insights into your business.

What is the difference between website analytics and Google Analytics? ›

It's important to note that Google Analytics is not the same as web analytics. Web analytics is a business process used to continuously improve your online business. Google Analytics is a tool to quantitatively measure what happens on your website.

Can I use the same Google Analytics for multiple websites? ›

  1. How many websites are you managing in Google Analytics? ...
  2. Know the difference between accounts, properties, and views. ...
  3. Add all sites under a single Google Analytics account. ...
  4. Create multiple views for each property. ...
  5. Add each site as unique accounts. ...
  6. Configure roll-up reporting. ...
  7. Add your tracking codes in Google Tag Manager.

What is the difference between free and paid Google Analytics? ›

Better custom data collection: The paid version of Google Analytics gives you more options with customizing your data collection. With Google Analytics 360, you get 200 custom dimensions and metrics instead of 20 with the free version. It allows you to customize your data collection to get more specific data.

Is Google Analytics free forever? ›

Google Analytics (GA) comes both as a free and paid version, called Google Analytics 360 (GA360). Small businesses can use the free service without paying a monthly charge, but if you want more advanced features, you will need to subscribe to Google 360 and pay a recurring fee.

What data can Google Analytics not collect? ›

Google Analytics cannot be used to track people across the web or apps. It does not create user profiles. Google Analytics helps owners of apps and websites understand how their users are engaging with their sites and apps (and only their site or app).

Does Google Analytics count my own visits? ›

The thing is, Google Analytics counts each visit to your website, including your own, as real data. And since you're not a 'real' visitor, you'd typically do things that your real audience wouldn't do, and as a result, you'll skew the accuracy of your data.

Can I connect any website to Google Analytics? ›

Add Analytics tracking

On a computer, open a classic Google Sites. Manage site. Use Universal Analytics. In the text box, under "Analytics Web Property ID," enter a valid Analytics Property ID.

Why is Google Analytics trying to track me? ›

Google uses personal data from Google Analytics, Global Site Tag, and from their many other trackers and products, so they can target you with advertising and content they think you'll want to see.

How do I turn off tracking activity? ›

On your Android phone, open the Settings app. Allow. At the bottom, tap Profile. Under “Tracking preferences,” turn Track your activities on or off.

How can you tell if someone is using Google Analytics? ›

6 ways to check if a website uses Google Analytics
  1. #1 Check the GA tag in the website source code.
  2. #2 Use the Developer Tools of your browser.
  3. #3 Use the Tag Assistant browser extension.
  4. #4 Check many webpages at once for UA.
  5. #5 Check your browser cookies.
  6. #6 Check Brave shield blocker.
Jan 18, 2023

Does Google Analytics track all users? ›

How does Google Analytics count users? Google Analytics counts users by generating a random string for the Client ID field, which gets stored within a user's browser cookie. However, different users aren't necessarily unique visitors.

Why avoid Google Analytics? ›

It uses cookies so you must obtain consent to store cookies. Google Analytics is a cookie-based web analytics tool and it is not possible to use it without cookies. Google Analytics sets multiple cookies and it “uses cookies to identify unique users across browsing sessions”.

Can tracking be turned off? ›

So, the general answer is no, your phone cannot be tracked when switched off. But this has been called into question numerous times. There have been talks of certain authorities still being able to track your phone when turned off.

Can someone track my phone without me knowing? ›

There is a way someone can monitor your mobile phone without ever touching the actual device. Spyware (a portmanteau of 'spying software) and stalkerware can be installed on a phone without the owner's knowledge, allowing an attacker to steal information, track activity, and more.

How do I stop Google from tracking everything I do online? ›

Turn "Do Not Track" on or off
  1. On your Android device, open the Chrome app .
  2. To the right of the address bar, tap More. Settings.
  3. Tap Privacy and security.
  4. Tap Do Not Track.
  5. Turn the setting on or off.


1. How WordPress Users Can Opt Out of Google Analytics Tracking
(Elegant Themes)
2. Google Analytics Opt-out – Tip 2 | Creative Handles
(Creative Handles)
3. Google Analytics GDPR Compliance – Make Your Site Compliant
4. How to use an opt out link during an email promotion
5. How to Make Google Analytics GDPR Compliant in WordPress
6. Act NOW. Google will automatically create GA4 properties. What to do?
(Analytics Mania - Google Tag Manager & Analytics)


Top Articles
Latest Posts
Article information

Author: Neely Ledner

Last Updated: 23/09/2023

Views: 5759

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.