If you are using Cookie Notice correctly for GDPR then you have probably moved your Google Analytics script to Cookie Notice’s script blocking text box.
If your visitor has yet to accept cookies the script is not served and Google Analytics does not run. If the user then accepts cookies Cookie Notice will reload the page with GA and it executes. However Google Analytics will record a reloaded page as a direct request (like navigation within your site) instead of an organic (off-site request).
As the CCA plugin is “managing” your visitors from outside the EU, we can ensure that, for these visitors at least, GA will is always served and executed so “organic” information is not lost; and CN will still block Analytics for EU visitors until acceptance.
Its a fairly simple solution but errors in the code could break your system; so only use if you know how to delete the script outside WordPress.
Note: this solution does not work for WPSC users – I have sent a revised script to a WPSC user for testing.
1. Copy the following code:
<?php
/*
Plugin Name: load my cookie scripts
Description: adds javascript to page if visitor is from EU or cookies are accepted
Version: 1.1
*/
if ( (function_exists('cca_is_EU') && ! cca_is_EU() ) ||
(function_exists('cn_cookies_accepted') && cn_cookies_accepted()) )
add_action( 'wp_head', 'load_my_cookie_scripts' );
function load_my_cookie_scripts() {
?>
<!-- OPTIONAL - see "Preventing Reload" in article below -->
//<script>document.cookie = "cca_is_eu=xyz;max-age=" + 3600*24*364 + "; path=/";</script>
<!-- insert your Google Analytics script here -->
<!-- insert other scripts if you wish -->
<?php
}
?>
2. Cut your GA script from Cookie Notice’s script blocking text box (image at top of page) and paste it into the code above in place of the yellow highlighted line.
3. Save as “cca_analytics_fix.php” in folder “”cca_analytics_fix” ;
4. Compress the folder into a Zip file (cca_analytics_fix.zip)
5. Ensure you have removed the GA script from Cookie Notice’s text box and saved CN settings. Then upload the zipped file via your WordPress Dashboard (plugins->add new->upload
) and activate.
Preventing Reload
If you have checked the “Reloading” option in Cookie Notice settings then the first page a new visitor lands on will be reloaded.
However; if you have included all javascript that depends on cookie acceptance in the above code then this is no longer necessary for your non EU visitors. You can delete the “//” from the beginning the pink highlighted line below “// OPTIONAL” to uncomment, and enable, code to prevent reload for non EU visitors.
.
Leave a Reply