Zurück zum Blog
Technical

Ship Faster: Cookie Consent in 5 Minutes for Modern Developers

GetCookies-TeamDecember 28, 202510 Min. Lesezeit
Quick StartNext.jsReactVueNuxtAstroSvelteKitInstallation

TLDR: Stop spending hours on cookie consent. GetCookies takes 5 minutes to install and handles GDPR, CCPA, and Google Consent Mode v2 automatically.

Read full summary

A practical guide for developers who want to add compliant cookie consent without derailing their sprint. Covers the 5-minute installation, framework integrations, CI/CD considerations, and common gotchas.

Summary by Claude AI

"Cookie Consent" Should Not Be a Two-Week Ticket

Last month, I watched a Jira ticket called "Add cookie consent banner" sit in sprint after sprint. Week one: research. Week two: vendor selection. Week three: GTM configuration. Week four: debugging.

By the time it shipped, the team had spent more time on cookie consent than on the actual feature that quarter.

Cookie consent shouldn't take a week. With GetCookies, it takes 5 minutes.

The Cookie Consent Time Sink

We've all been there. You're shipping a new feature, the deadline is tomorrow, and someone asks: "Wait, is our cookie banner GDPR compliant?"

Suddenly your afternoon looks like this:

  • 1 hour researching CMP options
  • 2 hours reading documentation
  • 1 hour setting up GTM triggers
  • 2 hours debugging why analytics broke
  • 1 hour on a call with the compliance team
  • Deadline missed

The 5-Minute Installation

Step 1: Get Your Domain ID (1 minute)

  1. Go to getcookies.co
  2. Sign up with email or Google
  3. Add your domain
  4. Copy your Domain ID

Step 2: Add the Script (30 seconds)

Add this to your <head>, before any tracking scripts:

<script src="https://getcookies.co/api/v1/widget/loader.js"
        data-domain-id="YOUR_DOMAIN_ID"
        async></script>

Step 3: Deploy (3 minutes)

git add .
git commit -m "Add cookie consent"
git push

Step 4: There is no Step 4

Your site now has:

  • GDPR-compliant cookie banner
  • CCPA support
  • Google Consent Mode v2 (with registered Developer ID)
  • Auto-blocking of tracking scripts
  • Third-party pixel consent (Meta, TikTok, etc.)

Framework-Specific Guides

Next.js / React

// app/layout.tsx or _document.tsx
import Script from 'next/script'

export default function RootLayout({ children }) {
  return (
    <html>
      <head>
        <Script
          src="https://getcookies.co/api/v1/widget/loader.js"
          data-domain-id="YOUR_DOMAIN_ID"
          strategy="afterInteractive"
        />
      </head>
      <body>{children}</body>
    </html>
  )
}

Nuxt 3 / Vue

// nuxt.config.ts
export default defineNuxtConfig({
  app: {
    head: {
      script: [
        {
          src: 'https://getcookies.co/api/v1/widget/loader.js',
          'data-domain-id': 'YOUR_DOMAIN_ID',
          async: true
        }
      ]
    }
  }
})

Astro

---
// src/layouts/Layout.astro
---
<html>
  <head>
    <script
      src="https://getcookies.co/api/v1/widget/loader.js"
      data-domain-id="YOUR_DOMAIN_ID"
      async
    ></script>
  </head>
  <body>
    <slot />
  </body>
</html>

SvelteKit

<!-- src/app.html -->
<head>
  <script
    src="https://getcookies.co/api/v1/widget/loader.js"
    data-domain-id="YOUR_DOMAIN_ID"
    async
  ></script>
</head>

Plain HTML

<!DOCTYPE html>
<html>
<head>
  <script src="https://getcookies.co/api/v1/widget/loader.js"
          data-domain-id="YOUR_DOMAIN_ID"
          async></script>
  <!-- Your other scripts -->
</head>
<body>
  <!-- Your content -->
</body>
</html>

What About GTM?

If you're using Google Tag Manager, GetCookies works with it seamlessly.

Option A: Direct Installation (Recommended)

Add GetCookies directly to your site's <head>, before the GTM snippet:

<head>
  <!-- GetCookies first -->
  <script src="https://getcookies.co/api/v1/widget/loader.js"
          data-domain-id="YOUR_DOMAIN_ID"
          async></script>

  <!-- GTM second -->
  <script>(function(w,d,s,l,i){...})(window,document,'script','dataLayer','GTM-XXXX');</script>
</head>

GetCookies automatically:

  • Sets consent defaults before GTM fires
  • Pushes getcookies_consent_update events to dataLayer
  • Provides getcookies_marketing and getcookies_analytics variables

No GTM configuration needed.

Conditional Script Loading

Need to load scripts only after consent? GetCookies makes it easy:

Using Data Attributes

<!-- This script only loads after analytics consent -->
<script
  data-cookieconsent="analytics"
  type="text/plain"
  src="https://www.googletagmanager.com/gtag/js?id=G-XXXX">
</script>

<!-- This script only loads after marketing consent -->
<script data-cookieconsent="marketing" type="text/plain">
  !function(f,b,e,v,n,t,s){...}  // Meta Pixel
</script>

Using the JavaScript API

// Wait for consent, then initialize
window.addEventListener('getcookies:consent', (e) => {
  const { analytics, marketing } = e.detail;

  if (analytics) {
    initializeGoogleAnalytics();
  }

  if (marketing) {
    initializeMetaPixel();
    initializeTikTokPixel();
  }
});

// Or check current state
if (window.GetCookies?.hasConsent('marketing')) {
  initializeMetaPixel();
}

Testing Cookie Consent

Manual Testing Checklist

  • Banner appears on first visit
  • "Accept All" grants all categories
  • "Reject All" grants only necessary
  • Preferences can be customized
  • Consent persists across page loads
  • Badge appears after consent (can reopen preferences)
  • Google Tag Assistant shows correct consent state
  • Analytics only fires after consent

Automated E2E Testing

// playwright.spec.js
test('cookie consent flow', async ({ page }) => {
  await page.goto('/');

  // Banner should appear
  await expect(page.locator('[data-getcookies-banner]')).toBeVisible();

  // Accept all
  await page.click('text=Accept All');

  // Banner should hide
  await expect(page.locator('[data-getcookies-banner]')).not.toBeVisible();

  // Reload - banner should not reappear
  await page.reload();
  await expect(page.locator('[data-getcookies-banner]')).not.toBeVisible();

  // Check localStorage
  const consent = await page.evaluate(() =>
    JSON.parse(localStorage.getItem('getcookies_consent'))
  );
  expect(consent.categories).toContain('analytics');
  expect(consent.categories).toContain('marketing');
});

CI/CD Integration

# .github/workflows/test.yml
name: E2E Tests
on: [push]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        run: npm ci
      - name: Run E2E tests
        run: npx playwright test
        env:
          GETCOOKIES_DOMAIN_ID: ${{ secrets.GETCOOKIES_DOMAIN_ID_TEST }}

Common Gotchas (and How to Avoid Them)

Gotcha 1: Script Order Matters

Wrong:

<script src="https://www.googletagmanager.com/gtag/js"></script>
<script src="https://getcookies.co/.../loader.js"></script>

Right:

<script src="https://getcookies.co/.../loader.js"></script>
<script src="https://www.googletagmanager.com/gtag/js"></script>

GetCookies must load first to set consent defaults before other scripts fire.

Gotcha 2: Caching

If you've deployed and don't see the banner, it might be cached. Clear your browser cache or test in incognito.

Gotcha 3: Content Security Policy

If you have a strict CSP, add GetCookies to your allowed sources:

Content-Security-Policy:
  script-src 'self' https://getcookies.co;
  connect-src 'self' https://getcookies.co;

Performance Best Practices

Use the Async Loader

The default async attribute is intentional. It allows your page to render while GetCookies loads:

<script src="..." async></script>  <!-- Good: doesn't block -->
<script src="..."></script>        <!-- Bad: blocks rendering -->

Preconnect for Faster Loading

<head>
  <link rel="preconnect" href="https://getcookies.co">
  <link rel="dns-prefetch" href="https://getcookies.co">
  <script src="https://getcookies.co/.../loader.js" async></script>
</head>

Bundle Size

  • GetCookies loader: ~1.6 KB (sets consent defaults immediately)
  • Full widget: ~20 KB (loads async after page render)

Your LCP isn't affected.

Ship It

Cookie consent doesn't have to be a project. With GetCookies:

  1. 5 minutes to install
  2. Zero GTM configuration required
  3. Automatic Google Consent Mode v2
  4. Built-in third-party pixel support
  5. Modern developer API

Stop reading documentation. Start shipping.

# Your next deploy
git add .
git commit -m "Add GDPR-compliant cookie consent"
git push origin main

GetCookies: Because cookie consent shouldn't be a sprint blocker.

Häufig gestellte Fragen

What frameworks does GetCookies support?
GetCookies works with any framework that renders HTML. We provide specific examples for Next.js, React, Vue, Nuxt, Astro, SvelteKit, and plain HTML. There are also WordPress and Shopify plugins.
Can I test GetCookies locally?
Yes, GetCookies automatically detects its API base from the script URL. You can create a separate domain for development/staging environments in the dashboard.
How do I handle script loading after consent?
GetCookies supports data-cookieconsent attributes on script tags, or you can use the JavaScript API with window.GetCookies.hasConsent() and event listeners for consent changes.
G

GetCookies-Team

Geschrieben und gepflegt vom GetCookies-Team der Getia AS in Oslo, Norwegen. Dieser Artikel ist eine allgemeine Information zur Cookie-Einwilligung und keine Rechtsberatung.

Scannen Sie Ihre eigene Website kostenlos

Im kostenlosen Plan läuft das Banner auf einer Website, dazu drei Cookie-Scans pro Monat. Keine Kreditkarte, kein Verkaufsgespräch.