GDPRChecker

Home / Knowledge Base / Google Maps Embeds React Cookie Consent: Setup, Blocking, and Testing Guide

Website Compliance

Google Maps Embeds React Cookie Consent: Setup, Blocking, and Testing Guide

A practical guide to implementing cookie consent for Google Maps embeds in React, covering step-by-step setup, common mistakes, and verification with GDPRChecker.

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

9 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.

Embedding Google Maps in a React application is a common way to display location data, but it also introduces privacy compliance obligations. Under regulations like the GDPR, loading Google Maps can set third‑party cookies and transmit personal data (such as IP addresses) to Google’s servers. This means you need a robust Google Maps embeds React cookie consent mechanism that blocks the map until the user has given explicit consent. In this guide, we’ll walk through the practical steps to implement such a solution, verify it with a scanner, and avoid common pitfalls. This is a technical implementation guide, not legal advice; always consult your legal team for compliance requirements.

Requirements and Compliance Expectations

Before diving into code, it’s important to understand the regulatory and technical landscape. The GDPR requires a legal basis for processing personal data; for non‑essential cookies and trackers, consent is the most common basis. The European Data Protection Board (EDPB) has clarified that cookie walls (forcing consent to access content) are not valid, so your map must not be essential to the service unless you can justify another legal basis.

Key compliance expectations: - Prior consent: No cookies from Google Maps should be set before the user takes an affirmative action (e.g., clicking “Accept”). - Granular choice: Users should be able to accept or reject map cookies independently of other categories, if your CMP supports it. - Transparency: Your privacy policy must disclose the use of Google Maps, the data shared, and the purposes. - Easy withdrawal: Users must be able to change their consent preference at any time, and the map should react accordingly (e.g., disappear or show a placeholder).

From a technical standpoint, Google recommends using Consent Mode for Google services. While Consent Mode primarily applies to tags like Google Analytics and Ads, the principle of adjusting behavior based on consent state is relevant. For maps, you can implement a similar pattern: check the consent state before initializing the API. If you use Google Tag Manager, you can set up triggers that fire only when consent is granted. However, the most reliable method is to control the rendering at the React component level.

How to Implement Step by Step

Implementing Google Maps embeds React cookie consent involves three main parts: setting up a CMP, creating a consent‑aware React component, and handling consent changes. Below is a step‑by‑step approach using a generic CMP that exposes a JavaScript API. Adjust the code to match your specific CMP (e.g., Cookiebot, OneTrust, or a custom solution).

Step 1: Choose and Configure a Consent Management Platform

First, integrate a CMP that can categorize Google Maps as a non‑essential service. In your CMP configuration, create a service or category (e.g., “External Maps”) and ensure it is set to “opt‑in” by default. The CMP should block any scripts or iframes associated with Google Maps until consent is given. Many CMPs provide automatic blocking, but for React applications, manual control is often more reliable.

Step 2: Build a Consent‑Aware Map Component

Create a React component that conditionally renders the map. Here’s a simplified example:

import React, { useState, useEffect } from 'react';

const GoogleMapEmbed = () => {
  const [consentGiven, setConsentGiven] = useState(false);

  useEffect(() => {
    // Check initial consent state from CMP
    if (window.cmp && window.cmp.hasConsent('maps')) {
      setConsentGiven(true);
    }

    // Listen for consent changes
    const handleConsentChange = (event) => {
      if (event.detail && event.detail.maps) {
        setConsentGiven(true);
      } else {
        setConsentGiven(false);
      }
    };

    window.addEventListener('consentChange', handleConsentChange);
    return () => window.removeEventListener('consentChange', handleConsentChange);
  }, []);

  if (!consentGiven) {
    return (
      <div className="map-placeholder">
        <p>We need your consent to load Google Maps.</p>
        <button onClick={() => window.cmp.showConsentModal()}>Manage Consent</button>
      </div>
    );
  }

  return (
    <iframe
      title="Google Map"
      src="https://www.google.com/maps/embed?pb=..."
      width="600"
      height="450"
      allowFullScreen
      loading="lazy"
    />
  );
};

export default GoogleMapEmbed;

This component checks the CMP’s consent state on mount and listens for updates. When consent is missing, it shows a placeholder with a button to open the consent preferences. Only when consent is granted does it render the iframe.

Step 3: Handle Dynamic Consent Changes

Users may withdraw consent later. Your component must react to this by removing the map and showing the placeholder again. The event listener in the example above handles this by updating the state. Additionally, you should clean up any map‑related DOM elements or event listeners to prevent memory leaks.

Step 4: Block Network Requests Proactively

Even with conditional rendering, there’s a risk that the iframe or API script could load before the consent check completes. To be safe, you can use a technique called “two‑step loading”: 1. On page load, do not include the map component at all. 2. After the CMP signals consent, dynamically import the component.

For example:

const GoogleMapEmbed = React.lazy(() => import('./GoogleMapEmbed'));

Then, in your main app, render it only when consent is confirmed. This ensures no map‑related code is even downloaded until consent is given.

Step 5: Integrate with Google Tag Manager (Optional)

If you use GTM to load the Maps API, set up a custom event trigger that fires only when the user has consented to the “maps” category. In your React app, push a dataLayer event when consent changes:

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: 'consent_update', maps_consent: true });

Then configure your GTM tag to fire on that event. This adds an extra layer of control, but the component‑level check remains the primary gate.

Common Mistakes and How to Avoid Them

Even well‑intentioned implementations can go wrong. Here are frequent pitfalls when setting up Google Maps embeds React cookie consent and how to steer clear of them.

1. Loading the Maps API Unconditionally

A common mistake is to include the Google Maps JavaScript API script in your index.html or via a package that loads it on mount. This triggers network requests before any consent check. Solution: Always load the API dynamically and only after consent. Use the loading attribute on the iframe or the async script loader with a consent gate.

2. Ignoring the “Reject” Flow

Many developers test only the “Accept” path. But what happens when a user clicks “Reject” or closes the banner without choosing? The map must remain blocked, and no cookies should be set. Solution: Test the reject flow thoroughly. Use browser developer tools to monitor network requests and cookies. Ensure the placeholder is displayed and no requests to Google domains are made.

3. Not Updating the Privacy Policy

Your privacy policy must list Google Maps as a data processor and explain what data is shared. If you add the map after the policy was last updated, you’re out of compliance. Solution: Review and update your privacy policy whenever you add new third‑party services. Link to Google’s privacy policy and describe the legal basis for processing.

4. Assuming One‑Time Consent Is Enough

Consent is not a one‑and‑done event. Users must be able to change their mind. If your component only checks consent on mount, a later withdrawal won’t remove the map. Solution: Implement the event listener pattern shown above. Also, provide a persistent “Cookie Settings” link that re‑opens the CMP.

5. Over‑Blocking or Under‑Blocking

Some CMPs block all iframes by default, which can break non‑tracking content. Others fail to block Google Maps because it loads via an iframe with a dynamic src. Solution: Test your blocking configuration. Use a scanner like GDPRChecker to verify that no cookies from google.com are set before consent. Adjust your CMP’s auto‑blocking rules or use manual control.

How to Validate with GDPRChecker

After implementing your consent solution, you must verify that it works correctly. Manual testing can miss edge cases, so using an automated scanner is essential. GDPRChecker’s scanning tool helps you validate Google Maps embeds React cookie consent by checking: - Pre‑consent network requests to Google domains. - Cookies set before and after consent. - Banner behavior (does it reappear? does it block correctly?). - Disclosure gaps in your privacy policy.

Running a Scan

  1. Deploy your changes to a staging environment.
  2. Enter the URL into GDPRChecker’s scanner.
  3. Configure the scan to simulate a first‑time visitor (no existing consent).
  4. Review the report for any unauthorized requests or cookies.
  5. Repeat the scan after accepting and rejecting consent to ensure the map behaves accordingly.

GDPRChecker scans help verify pre‑consent network requests, banner behavior, and disclosure gaps after changes. If the scan flags issues, you can drill down into the specific requests and adjust your implementation. Regular scanning is recommended, especially after updating your CMP, adding new embeds, or changing your privacy policy.

For a deeper dive into related compliance topics, see our guides on Google Analytics GDPR compliance and Google Consent Mode v2. If you’re unsure whether you need a CMP, read Do I need a CMP if I do not run Google Ads?.

Implementation Checklist

Use this checklist to ensure your Google Maps embeds React cookie consent setup is complete and verifiable:

  1. Integrate a CMP that supports granular consent categories.
  2. Configure a “maps” or “external content” category set to opt‑in by default.
  3. Update your privacy policy to disclose Google Maps data processing.
  4. Build a React component that conditionally renders the map based on consent.
  5. Add a placeholder with a clear message and a link to consent settings.
  6. Implement an event listener to handle consent changes (accept/withdraw).
  7. Ensure the Maps API script or iframe is not loaded until consent is given.
  8. Test the reject flow: no cookies or requests to Google domains before consent.
  9. Test the accept flow: map loads correctly after consent.
  10. Verify that withdrawing consent removes the map and stops further requests.
  11. Run a GDPRChecker scan on a staging URL to catch any pre‑consent leaks.
  12. Schedule periodic scans to maintain compliance as your site evolves.

FAQ

What is Google Maps embeds React cookie consent?

It’s the practice of conditionally loading Google Maps in a React app only after the user has given explicit consent via a cookie banner. This prevents non‑essential cookies and data transfers before consent, helping meet GDPR and ePrivacy requirements.

Do I need Google Maps embeds React cookie consent for GDPR?

Yes, if your website targets EU users and embeds Google Maps. The embed sets third‑party cookies and shares personal data like IP addresses, which requires prior consent under the GDPR unless you can rely on another legal basis.

How do I implement Google Maps embeds React cookie consent?

Integrate a CMP, create a React component that checks consent state before rendering the map, and listen for consent changes to show/hide the map dynamically. Block the Maps API script until consent is confirmed.

How can I verify Google Maps embeds React cookie consent with a scanner?

Use GDPRChecker’s scanner to simulate a first‑time visit. It checks for pre‑consent network requests to Google domains, unauthorized cookies, and banner behavior. Run scans after implementation and periodically to catch regressions.

What are common Google Maps embeds React cookie consent mistakes?

Common mistakes include loading the Maps API unconditionally, not testing the reject flow, forgetting to update the privacy policy, ignoring consent withdrawal, and misconfiguring the CMP’s auto‑blocking. Regular scanning helps catch these issues.

Conclusion

Implementing Google Maps embeds React cookie consent is a critical step for any React website that uses Google Maps and must comply with GDPR. By conditionally loading the map based on user consent, you respect privacy while maintaining functionality. Remember to test both accept and reject flows, keep your privacy policy up to date, and validate your setup with a scanner like GDPRChecker. For further reading, explore our guides on Consent Mode v2 vs Google Certified CMP and Cookie Banner Requirements.

Ready to verify your implementation? Run a GDPRChecker scan today to ensure your Google Maps embeds are fully compliant.

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