Integration with Google Analytics 4

Nelson
Written by NelsonLast updated 19 days ago

There are two methods to collect cookie banner analytics: using either CookieScript cookie banner analytics tool or Google Analytics 4. You could use CookieScript cookie banner analytics, Google Analytics 4, or both.

You can easily connect Google Analytics 4 with a CookieScript pop-up on your website or app.

See the guides:

How to enable Google Analytics 4?

How to select Google Analytics 4 as your main analytics tool?

How to read Google Analytics 4 statistics?

Watch a video on how to connect Google Analytics 4 and CookieScript:

Besides Google Analytics 4, you can also use CookieScript Cookie Banner Analytics.

Integration with Google Analytics 4 is included in the Plus pricing plan.

If you are using Google Analytics 4 (GA4) together with CookieScript and Google Consent Mode, here is what happens behind the scenes when visitors accept or decline cookies. This explains why certain cookies may still appear in the browser even after consent is withdrawn.

When a visitor first opens your website:

  • Analytics consent is treated as denied by default.

  • GA4 does not set or read analytics cookies like _ga or _gid.

  • If Advanced Consent Mode is enabled, GA4 may send only anonymous, aggregated, cookieless pings until a choice is made.

This behavior is compliant with GDPR and ePrivacy requirements.

When the User Clicks “Accept All”

After the visitor accepts all cookies:

  • CookieScript sends a consent granted signal to Google.

  • GA4 switches to full-cookie mode.

  • Analytics cookies (_ga, _gid, etc.) are created normally.

  • GA4 tracks visits and events with standard identifiers.

When the User Later Clicks “Decline All”

If the visitor withdraws consent later:

  • CookieScript updates Google with a consent withdrawn signal.

  • GA4 immediately switches to restricted, cookieless mode.

  • Existing analytics cookies may still appear in the browser’s storage, but:

    • GA4 stops reading or updating them, and

    • No new analytics cookies are created.

All tracking becomes limited to anonymous, aggregated pings that do not rely on identifiers.

Why Analytics Cookies Are Not Always Deleted

GDPR requires that processing stops after consent is withdrawn. It does not require that cookie files must always be forcibly removed.

Some cookies may remain because:

  • They were created with certain security flags (e.g., Secure, HttpOnly).

  • They were set in ways that cannot reliably be deleted from JavaScript.

  • Browsers restrict the removal of specific third-party cookies.

What matters is that the cookies are no longer used, not that they no longer exist. CookieScript and Consent Mode ensure GA4 fully stops using them.

How to Verify This Yourself

You can test GA4 consent behavior directly in your browser.

Check GA4 Network Requests

  1. Open your site in Chrome.

  2. Press F12 to open Developer Tools.

  3. Go to the Network tab.

  4. Filter by “collect”.

  5. Reload the page.

After Accepting All Cookies:
Look for GA4 requests containing:

  • gcs=G111 → consent granted

  • npa=0 → personalized allowed (if used)

After Declining All Cookies:
Reload and check again:

  • gcs=G100 → analytics consent denied

  • npa=1 → non-personalized only

  • Some setups may also show pscdl=denied → cookieless mode

gcs=G100 confirms GA4 is not using analytics cookies.

  1. Open Application / Storage in Developer Tools.

  2. Look under Cookies → your domain.

If the user accepted cookies:

  • _ga and _gid appear and update on reload.

If the user declined cookies:

  • An existing _ga may still be present, but it stops updating.

  • New users who decline immediately will not receive a _ga cookie at all.

Summary

  • Old analytics cookies may remain in storage, but GA4 no longer uses them once consent is denied.

  • No new analytics cookies are created without explicit consent.

  • CookieScript and Consent Mode together ensure fully compliant, privacy-respecting behavior.

Did this article help you solve your issue?