


This will help you to avoid the " Uncaught ReferenceError: Drupal is not defined" message you have been seeing. Google Analytics provides detailed statistics about visitor traffic to your site. This approach is a bit more work, but it will prevent scripts and cookies from being loaded at all before consent is granted.įinally, I should note that based on your comments here and on, I think you should do some research on " Drupal Behaviors" for your JavaScript. You can simply add the following code to the Advanced Settings->Custom JS in Google Analytics: if (!_cookie_compliance.hasAgreed())) Moving from Google Analytics to Google Tag Manager on Drupal Sites. I've personally used this to prevent third-party code snippets from loading until after compliance is granted, by making a custom module and including the call to hasAgreed() in my module's JavaScript behaviors.īut as the first example above shows, a custom module is not necessary for Google Analytics in particular. On the top menu bar, click Configuration. Under STATISTICS, locate Google Analytics, select the ENABLED check box, and then click Save configuration.
DRUPAL GOOGLE ANALYTICS HOW TO
Here is another example showing how to set cookies after user clicks zip file on your local computer, and then click Install. JavaScript function provided that returns TRUE if the user has givenįor example, if you want to disable Google Analytics, you could do theĪnother example of how it can be used with Google Analytics is If you want to conditionally set cookies in your module, there is a Note: Our official Drupal module is no longer actively maintained but should still work. Drupal Google Analytics - Setup and Installation : 1. The google analytics integration with Drupal allows the use and customization of numerous features to change things up from the usual pattern. From the EU Cookie Compliance module's project page on : In Drupal, the Drupal Google Analytics module used by almost 400,000 sites, is among the top 20 most popular modules.
