GDPRChecker

Home / Knowledge Base / Google Analytics 4 Vue Cookie Consent: Setup, Blocking, and Testing

Website Compliance

Google Analytics 4 Vue Cookie Consent: Setup, Blocking, and Testing

A practical guide for Vue.js developers on implementing Google Analytics 4 cookie consent. Covers step-by-step setup, blocking pre-consent requests, common mistakes, and verification with GDPRChecker scans.

Run a free GDPR compliance scanPreview the findings before choosing a CMP.

Author

GDPRChecker Editorial Team

Reviewed by

Privacy & Compliance Research Team

Last updated

July 2026

Reading time

10 min read

Educational guidance for compliance readiness — not legal advice. Requirements vary by jurisdiction and your specific processing activities.

Introduction

Updated for 2026 compliance practices.

Google Analytics 4 Vue cookie consent is a practical compliance topic for website owners validating consent, tags, and disclosures. If you run a Vue.js application and use Google Analytics 4 (GA4), you need to ensure that tracking scripts respect user consent choices. This guide walks through the technical steps to implement cookie consent in a Vue project, block GA4 until consent is given, and verify everything works correctly. We focus on actionable implementation details, common pitfalls, and how to validate your setup using GDPRChecker’s scanning tools.

Important: This guide provides technical implementation guidance, not legal advice. For legal questions, consult a qualified professional. The requirements discussed are based on general principles of data protection law, particularly the GDPR, but your specific obligations may vary.

Requirements and Compliance Expectations

Before diving into code, let’s clarify the key compliance expectations for GA4 on a Vue site. These are based on official guidance from Google and European data protection authorities.

Consent Must Be Prior and Granular

Consent must be obtained before any non-essential cookies are set or any personal data is processed. For GA4, this means you cannot initialize the analytics library or send any hits until the user has explicitly agreed. Moreover, consent should be granular: users should be able to accept analytics cookies separately from marketing cookies, for example.

Blocking Pre-Consent Requests

A common mistake is to load the GA4 script but delay sending hits. Even loading the script can set cookies or transmit data (like IP address) in the request headers. Therefore, you must block the script entirely until consent is given. This can be done by conditionally injecting the script tag or by using a tag manager that respects consent signals.

Consent Mode Integration

Google’s Consent Mode allows you to adjust how Google tags behave based on consent state. For GA4, you can send a default consent state of 'denied' and update it to 'granted' when the user consents. This ensures that even if a tag fires, it will operate in a cookieless mode until consent is given. However, Consent Mode alone does not replace the need for a consent banner; it’s a complementary mechanism. You can learn more in our guide on Google Consent Mode v2.

Cookie Banner and Privacy Policy

Your site must display a cookie banner that: - Informs users about the use of cookies and their purposes. - Obtains affirmative consent before setting non-essential cookies. - Provides a clear option to reject all non-essential cookies. - Links to a comprehensive privacy policy.

The privacy policy should disclose the use of GA4, the data it collects, and how users can exercise their rights. For more details, see our cookie banner requirements guide.

Ongoing Verification

Compliance is not a one-time task. After any changes to your Vue app, tag configuration, or consent setup, you should re-verify that everything works as expected. GDPRChecker’s scanner can automate this by checking for pre-consent requests, banner behavior, and disclosure gaps.

Common Mistakes and How to Avoid Them

Even with careful implementation, several pitfalls can undermine your compliance. Here are the most frequent issues and how to address them.

1. Loading GA4 Before Consent

The most critical mistake is firing the GA4 script or sending hits before the user has consented. This often happens when developers place the GA4 snippet directly in index.html without any conditional logic. Always use a consent gate before loading the script.

Verification: Use GDPRChecker’s scanner to check for pre-consent network requests. It will flag any requests to google-analytics.com or googletagmanager.com that occur before consent.

2. Ignoring the Reject Flow

Many implementations only handle the “Accept” path. If a user clicks “Reject”, you must ensure that no analytics cookies are set and that the GA4 script is not loaded. Test the reject flow thoroughly: after rejecting, refresh the page and confirm that no GA4 requests appear in the network tab.

3. Not Updating Consent Mode Defaults

If you use Consent Mode but forget to set the default to 'denied', Google tags may still set cookies even without consent. Always set the default before any tag fires.

4. Incomplete Privacy Policy Disclosures

Your privacy policy must mention GA4 specifically, including the types of data collected and the purposes. It should also explain how users can exercise their data subject rights. GDPRChecker’s scanner can identify gaps in your policy disclosures.

5. Forgetting About Subdomains or Embedded Content

If your Vue app loads content from other domains (e.g., embedded videos, social media widgets), those may also set cookies. Ensure your consent solution covers all third-party resources, not just GA4.

6. Relying Solely on Consent Mode Without a Banner

Consent Mode is not a replacement for a cookie banner. You still need to obtain explicit consent. Consent Mode only adjusts tag behavior; it doesn’t collect consent.

Implementation Checklist

Use this checklist to ensure you’ve covered all bases:

  1. Consent state is managed in a reactive store (Pinia/Vuex) and persisted.
  2. Cookie banner is displayed on first visit and blocks interaction until a choice is made.
  3. Banner includes clear “Accept All”, “Reject All”, and “Customize” options.
  4. Rejecting is as easy as accepting (no dark patterns).
  5. GA4 script is loaded only after analytics consent is granted.
  6. Consent Mode defaults are set to 'denied' before any tags fire.
  7. Consent Mode is updated to 'granted' when consent is given.
  8. Page views and events are only sent after consent.
  9. A persistent “Cookie Settings” link allows users to change consent.
  10. Privacy policy discloses GA4 data collection and user rights.
  11. Pre-consent network requests are verified using GDPRChecker scanner.
  12. Full reject flow is tested: no GA4 requests after rejection.

FAQ

What is Google Analytics 4 Vue cookie consent?

Google Analytics 4 Vue cookie consent refers to the technical implementation of obtaining and respecting user consent before loading GA4 tracking scripts in a Vue.js application. It involves conditionally loading GA4 based on user choices, typically managed through a cookie banner and consent state management.

Do I need Google Analytics 4 Vue cookie consent for GDPR?

Yes, if your Vue site targets users in the European Economic Area, you must obtain prior consent before setting GA4 cookies, as they are not strictly necessary. This applies regardless of whether you use a CMP or a custom solution.

How do I implement Google Analytics 4 Vue cookie consent?

Implement by: 1) creating a consent state store, 2) building a cookie banner that sets consent flags, 3) conditionally loading the GA4 script only when analytics consent is true, and 4) optionally integrating Google Consent Mode. Always test the reject flow.

How can I verify Google Analytics 4 Vue cookie consent with a scanner?

Use GDPRChecker to scan your site. It checks for pre-consent network requests to Google domains, verifies banner behavior, and identifies disclosure gaps in your privacy policy. Run scans after any changes to maintain compliance.

What are common Google Analytics 4 Vue cookie consent mistakes?

Common mistakes include loading GA4 before consent, ignoring the reject flow, not setting Consent Mode defaults to denied, incomplete privacy policy disclosures, and forgetting about third-party cookies from embedded content.

Next step

Run a GDPRChecker scan to validate consent behavior, trackers, and disclosures after you implement the checklist above.

GDPRChecker guides are educational resources and do not constitute legal advice. Use them to understand technical and operational privacy requirements, and consult qualified counsel for legal interpretation.

Check Your Website in Under 60 Seconds

  • Sign in required
  • GDPR-focused checks
  • Cookie banner detection
  • Privacy policy verification