Why Isn't My Google Analytics Script Working with GDPR Cookie Compliance?
Content
Integrating Google Analytics with the 'GDPR Cookie Compliance' plugin is a common setup, but it can sometimes lead to confusion. A frequent issue users report is that their Analytics script doesn't seem to load or track data correctly after being moved into the plugin's settings. This guide will walk you through the most common reasons for this problem and how to fix them.
The Core Principle: How the Plugin Manages Scripts
First, it's crucial to understand how the plugin operates. To be compliant with GDPR and similar regulations, the plugin must prevent tracking scripts from loading until a user gives their consent. It does this by dynamically injecting the scripts you define (like Google Analytics) into your page using JavaScript after the user clicks 'Accept'.
Common Problems and Their Solutions
1. The Script Isn't Visible in the Page Source
Problem: You've added your Google Analytics code to the '3rd Party Cookies' section, accepted cookies on your site, but when you right-click and select 'View Page Source', you can't find the script.
Why This Happens: This is expected behavior. The plugin injects the scripts dynamically with JavaScript after the page has already loaded. The initial HTML source code served from the server will not contain these scripts.
Solution: To verify the script is loading, you must use your browser's Developer Tools (Inspect Element).
- Open your website and accept cookies.
- Right-click and choose Inspect.
- Go to the Elements tab and search (Ctrl+F / Cmd+F) for part of your script, like
gtagorGoogleAnalyticsObject. - Alternatively, check the Network tab and look for calls to
google-analytics.comorgoogletagmanager.com.
2. Caching or Browser Extensions Are Interfering
Problem: You've configured everything correctly, but Google Analytics still isn't receiving data.
Why This Happens: Your browser's cache might be serving an old version of the page without the consent logic. Additionally, ad-blocker or privacy extensions can block tracking scripts from loading, even after they are consented to.
Solution: Always test in a private/incognito browsing window and ensure any ad-blocking extensions are temporarily disabled. Also, clear any server-side or plugin caches (e.g., from WP Rocket, W3 Total Cache) after changing your plugin settings.
3. The Original Script Is Still Hardcoded
Problem: Google Analytics is tracking users even before they accept cookies.
Why This Happens: The most common reason for this is that the original Google Analytics script was not removed from its previous location. The plugin cannot block a script that is hardcoded into your theme or another plugin.
Solution: You must find and remove the original Google Analytics code. Common places to check include:
- Your theme's header/footer settings (e.g., in the WordPress Customizer).
- Dedicated analytics plugins (e.g., MonsterInsights, ExactMetrics). You may need to disable tracking in those plugins' settings.
- Your theme's
header.phporfunctions.phpfiles.
4. Incorrect Script Format in the Plugin Settings
Problem: The script is not being executed properly after injection.
Why This Happens: The script might be malformed or missing required elements.
Solution: Ensure you are pasting the complete script tag provided by Google. For a standard gtag.js implementation, it should look something like this:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-X');
</script>
Make sure this entire block of code is placed in the Head section of the '3rd Party Cookies' tab in the plugin settings.
5. A 403 Forbidden Error When Saving
Problem: You get a "403 Forbidden" error when trying to save your script in the plugin's settings page.
Why This Happens: This is typically a server-level permission issue or a conflict with your theme's security settings, often triggered when trying to save code containing <script> tags.
Solution: A potential workaround is to add the following code snippet to your theme's functions.php file. This changes the capability required to edit the plugin's settings.
add_action( 'gdpr_options_page_cap', function( $capability ){
return 'edit_posts';
});
Warning: Editing theme files is an advanced step. Always use a child theme and create a backup first.
Final Verification
After implementing these solutions, the best way to verify everything is working is to:
- Open your site in an incognito window.
- Do not accept cookies. Check your Google Analytics Real-Time report—you should see no active users.
- Reload the page and accept cookies. You should now see your visit appear in the Real-Time report within seconds.
By following these steps, you can resolve the vast majority of issues related to integrating Google Analytics with the 'GDPR Cookie Compliance' plugin.
Related Support Threads Support
-
Cookies (e.g. Google Analytics) are being loaded by defaulthttps://wordpress.org/support/topic/cookies-e-g-google-analytics-are-being-loaded-by-default/
-
third-party cookies are not visiblehttps://wordpress.org/support/topic/additional-cookies-and-third-party-cookies-are-not-visible/
-
Scripts/Cookies not appearing in Headerhttps://wordpress.org/support/topic/scripts-cookies-not-appearing-in-header/
-
Google Analytics – Code not added?https://wordpress.org/support/topic/google-analytics-code-not-added/
-
Google analytic opt-out only works in one pagehttps://wordpress.org/support/topic/google-analytic-opt-out-only-works-in-one-page/
-
Opt-Outhttps://wordpress.org/support/topic/opt-out-5/
-
Noob need help foor google analytics and adshttps://wordpress.org/support/topic/noob-need-help-foor-google-analytics-and-ads/
-
3rd party by default enabledhttps://wordpress.org/support/topic/3rd-party-by-default-enabled/
-
3rd party Sccipt code is not loadinghttps://wordpress.org/support/topic/3rd-party-sccipt-code-is-not-loading/
-
Configuration third-party cookieshttps://wordpress.org/support/topic/configuration-third-party-cookies/
-
problem additional cookieshttps://wordpress.org/support/topic/problem-additional-cookies/
-
Custom code not workinghttps://wordpress.org/support/topic/custom-code-not-working-3/
-
why SEARCH_SAMESITE loads or nothttps://wordpress.org/support/topic/why-search_samesite-loads-or-not/
-
Google Analytics works before cookies acceptancehttps://wordpress.org/support/topic/google-analytics-works-before-cookies-acceptance/
-
Enable/disable Facebook & Google Analytics cookiehttps://wordpress.org/support/topic/enable-disable-facebook-google-analytics-cookie/
-
Google Analytics not workinghttps://wordpress.org/support/topic/google-analytics-not-working-33/
-
_ga, _gat, _gidhttps://wordpress.org/support/topic/_ga-_gat-_gid/
-
Third party GA snippet not written to headerhttps://wordpress.org/support/topic/third-party-ga-snippet-not-written/
-
GTM code is not implemented after clicking accept allhttps://wordpress.org/support/topic/gtm-code-is-not-implemented-after-clicking-accept-all/
-
Google analyticshttps://wordpress.org/support/topic/google-analytics-183/
-
Newbie cookie code helphttps://wordpress.org/support/topic/newbie-cookie-code-help/
-
Not quite the finished articlehttps://wordpress.org/support/topic/not-quite-the-finished-article/
-
How to set uphttps://wordpress.org/support/topic/how-to-set-up-12/
-
Remote script failedhttps://wordpress.org/support/topic/remote-script-failed/
-
Help for the gdpr plugin insert google analyticshttps://wordpress.org/support/topic/help-for-the-gdpr-plugin-insert-google-analytics/
-
Google Analytics not workinghttps://wordpress.org/support/topic/google-analytics-not-working-25/
-
Functional cookieshttps://wordpress.org/support/topic/functional-cookies/
-
How do I know if the cookies are working?https://wordpress.org/support/topic/how-do-i-know-if-the-cookies-are-working/
-
Script snippethttps://wordpress.org/support/topic/script-snippet/
-
Google Analytics scripthttps://wordpress.org/support/topic/google-analytics-script-4/
-
Losing referrer header in GAhttps://wordpress.org/support/topic/losing-referrer-header-in-ga/
-
Google Analytics Code Not Added On Enablehttps://wordpress.org/support/topic/google-analytics-code-not-added-on-enable/
-
ERR_BLOCKED_BY_CLIENThttps://wordpress.org/support/topic/err_blocked_by_client-2/
-
Changing priority of third party cookiehttps://wordpress.org/support/topic/changing-priority-of-third-party-cookie/
-
Gonsent mode v2: G111 response but data not tracked to Google Analyticshttps://wordpress.org/support/topic/gonsent-mode-v2-g111-response-but-data-not-tracked-to-google-analytics/
-
Separating Marketing and Analytics with GTMhttps://wordpress.org/support/topic/separating-marketing-and-analytics-with-gtm/
-
Example scripts for 3rd Party Cookies, please!https://wordpress.org/support/topic/example-scripts-for-3rd-party-cookies-please/
-
Third Parties Cookie Issuehttps://wordpress.org/support/topic/third-parties-cookie-issue/
-
Third party cookies errorhttps://wordpress.org/support/topic/third-party-cookies-error-2/
-
Problem with Google analitycshttps://wordpress.org/support/topic/problem-with-google-analitycs/
-
Google Tag Manager Integrationhttps://wordpress.org/support/topic/google-tag-manager-integration-5/
-
Auto accept and decline cookieshttps://wordpress.org/support/topic/auto-accept-and-decline-cookies/
-
Error: remote script failedhttps://wordpress.org/support/topic/error-remote-script-failed/
-
How to include 3rd party script?https://wordpress.org/support/topic/how-to-include-3rd-party-script/
-
Monster Insight Cookieshttps://wordpress.org/support/topic/monster-insight-cookies/
-
Cookie pop-up appears, but settings and Accept links don’t go anywherehttps://wordpress.org/support/topic/cookie-pop-up-appears-but-settings-and-accept-links-dont-go-anywhere/
-
403 Forbidden Error saving third-party cookieshttps://wordpress.org/support/topic/403-forbidden-error-saving-third-party-cookies/
-
Analytics missinghttps://wordpress.org/support/topic/analytics-missing/
-
Add to cart conversion snippet – Google Analyticshttps://wordpress.org/support/topic/add-to-cart-conversion-snippet-google-analytics/
-
Google Analyticshttps://wordpress.org/support/topic/google-analytics-177/
-
creation of google analytics scripthttps://wordpress.org/support/topic/creation-of-google-analytics-script/
-
Clicking “Enable All” generates my Google Analytics script twicehttps://wordpress.org/support/topic/clicking-enable-all-generates-my-google-analytics-script-twice/
-
Adding AW-XXXXX to track google ad conversionshttps://wordpress.org/support/topic/adding-aw-xxxxx-to-track-google-ad-conversions/