How to Handle Opt-Ins for Google Analytics

Cody Schneider••8 min read

Using Google Analytics isn't just about adding a tracking snippet to your site anymore. To comply with modern privacy regulations like GDPR and ePrivacy, you need explicit permission from your users before you can collect their data. This post will walk you through exactly how to handle Google Analytics opt-ins, explaining what's changed and providing a step-by-step guide to making your site compliant without losing all your valuable insights.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Why Is Everyone Talking About Cookie Opt-Ins Now?

Cookie consent banners aren't exactly new, but getting it right has become urgent. Regulations like Europe's General Data Protection Regulation (GDPR) have long required user consent for data collection. More recently, the Digital Markets Act (DMA) has pushed Google to strictly enforce these rules for its advertising and analytics products.

As of March 2024, Google requires all websites collecting data from users in the European Economic Area (EEA) to implement Google Consent Mode v2. In simple terms: if you don’t have a compliant opt-in system that communicates with Google, you will see a significant drop in analytics data, and your advertising features like remarketing and personalized ads will stop working for EEA users.

What is Google Consent Mode v2?

First, it's important to understand what Consent Mode is and isn't. It is not a cookie banner. Instead, it’s a behind-the-scenes API that acts as a communication channel between your website's consent banner and Google’s tags (like your Google Analytics and Google Ads scripts).

When a user makes a choice on your cookie banner (e.g., clicking “Accept” or “Decline”), the banner communicates that choice to Consent Mode. Consent Mode then tells Google's scripts how to behave. It controls two primary consent types relevant to Google Analytics:

  • analytics_storage: Controls whether Google Analytics can store cookies to measure user behavior.
  • ad_storage: Controls whether cookies can be stored for advertising purposes.

For each type, the user’s choice can be granted or denied. This is where you see two different ways of implementing Consent Mode.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Basic vs. Advanced Consent Mode Implementation

You have two options for setting up Consent Mode, and the choice impacts how much data you can recover.

Basic Implementation:

  • Super straightforward and privacy-first.
  • Google's tags are completely blocked from loading until a user consents.
  • If a user clicks "Decline" or doesn't interact with the banner, no information is sent to Google, not even anonymously.
  • Downside: You lose a lot of visibility into your opted-out traffic.

Advanced Implementation:

  • This is the method Google recommends and is the most common setup.
  • Google's tags load before the consent banner appears, but they operate in a restricted, cookieless state.
  • If a user clicks "Decline," the tags will send anonymous, aggregated "pings" to Google Analytics without using cookies.
  • Benefit: These cookieless pings allow Google to use data modeling to fill in gaps in your reporting created by users who opt out, giving you a more complete picture of your site's performance.

For the rest of this guide, we will focus on the Advanced implementation, as it offers the best balance of compliance and data-driven insight.

Step 1: Get a Consent Management Platform (CMP)

Trying to build a compliant opt-in system from scratch is a massive headache. A Consent Management Platform (CMP) is a tool that handles the heavy lifting for you. It provides the cookie banner itself, records user consent, and integrates with technologies like Google Consent Mode.

Dozens of great options are on the market, but you should look for one that is a Google Certified CMP. This ensures it's been vetted by Google to work flawlessly with Consent Mode v2. Some popular choices include:

  • CookieYes: Known for its ease of use and generous free plan.
  • Cookiebot by Usercentrics: A powerful and highly customizable option for businesses of all sizes.
  • Iubenda: Offers an all-in-one suite for compliance, including privacy policies and terms of service generators.

After choosing your CMP, the initial setup process typically involves signing up, adding your website's URL, and letting the tool scan your site to automatically discover and categorize the cookies you're using.

Step 2: Configure Your Cookie Banner

Once your CMP has scanned your site, you’ll customize the banner that users will see. While the specific settings vary between platforms, the core steps are universal.

  1. Customize the Appearance: Adjust the colors, text, and layout of your banner to match your website's branding.
  2. Edit the Text: Clearly explain why you are collecting data and what it's used for. Use plain language, not legal jargon.
  3. Set Up Your Buttons: Compliance laws (especially in the EU) require that rejecting consent is as easy as accepting it. Make sure you have clear "Accept" and "Decline" buttons. You should also include a "Customize" or "Settings" link that allows users to pick which types of cookies (e.g., analytics, marketing) they consent to.
  4. Configure the Default State: In most privacy-conscious regions, no cookies besides those that are "strictly necessary" can be set until the user has actively opted in. Configure your banner so that all non-essential categories (like Analytics and Marketing) are turned off by default.

Step 3: Deploy the Banner & Activate Consent Mode

Once your banner is configured, you'll need to add it to your website and ensure it's communicating with Google. This is surprisingly simple with a Google Certified CMP.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Adding The CMP Script To Your Site

Your CMP will give you a small JavaScript snippet. This code needs to be placed in the <head> section of your website’s HTML. It’s crucial to place it here, as it needs to load before any other tracking scripts (like Google Analytics or Facebook Pixel) so it can manage their behavior based on user consent.

If you use a CMS like WordPress or Shopify, your CMP likely has a plugin or app that makes installation as easy as copying and pasting an ID - no code editing required.

Turn on Google Consent Mode

This is the magical step. In your CMP's dashboard, there will typically be a settings section for integrations or compliance frameworks. Find the option for "Google Consent Mode" and simply toggle it on.

That's it! Behind the scenes, the CMP is now configured to automatically send the correct consent signals (granted or denied) to Google’s tags based on the user's interaction with your banner. You don’t need to do any complex manual setup in most cases.

For advanced use cases or if you're not using a CMP with a turnkey integration, you can also set up Consent Mode manually via Google Tag Manager (GTM). This involves setting a default consent command to deny storage for all categories, and then creating triggers that update the consent based on custom events fired by your banner when a user accepts.

Here’s a conceptual example of a default command you might configure in a GTM tag:

gtag('consent', 'default', {
  'analytics_storage': 'denied',
  'ad_storage': 'denied',
  'ad_user_data': 'denied',
  'ad_personalization': 'denied',
  'wait_for_update': 500
}),

This tells Google to deny all storage by default. Your CMP would then fire an "update" command after the user consents, changing 'denied' to 'granted'. Thankfully, modern CMPs manage all of this for you when you flick that switch.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

What Actually Happens When a User Clicks "Decline"?

This is where marketers often get worried. Does a "decline" mean you've lost all visibility into that user's session? With Advanced Consent Mode, the answer is no.

When analytics_storage is 'denied', your Google Analytics tag sends cookieless pings. These are anonymous signals that don't - and can't - personally identify a user, but they do provide essential, aggregated information like:

  • The number of users who visit a page.
  • A timestamp of a session.
  • The country the user is visiting from.
  • Indication that a conversion event occurred (e.g., a form submission).

Google Analytics then takes this aggregate data from your opted-out users and combines it with the detailed, cookie-based data from your opted-in users. Using machine learning, it creates Behavioral and Conversion Models to fill the reporting gaps. So while you won’t be able to analyze an individual opted-out user’s journey, your top-line reports on sessions, audience demographics, and conversions will remain remarkably accurate.

Final Thoughts

Setting up a Google Analytics opt-in system is now a fundamental part of responsible data collection. By using a Google Certified Consent Management Platform, you can deploy a compliant banner and enable Consent Mode v2 quickly, ensuring you respect user privacy while preserving the integrity of your key performance data through modeling.

Once your data is flowing in compliantly, the next step is making sense of it all. We built Graphed because we know that getting insights shouldn't require complex configuration or hours spent navigating different platforms. You can connect your Google Analytics account in seconds and use simple, natural language to create real-time dashboards and ask questions about your marketing performance, letting you focus on the insights that drive growth.

Related Articles