I use the GoogleAnalytics module in most of my projects and have often the same issue:

Due to my countries policy requirements, every user has to be able to deactivate google-analytics cookies. To do so I need a little JavaScript to disable the cookie wich contains the UA/property ID, which is provided by the module.

Normaly such configs are set in the drupal-settings-json at the end of the page but there is no property-id in sight.

<script type="application/json" data-drupal-selector="drupal-settings-json">{"path":{"baseUrl":"\/","scriptPath":null,"pathPrefix":"","current....

is there any way for my JS-function to access this infirmation, or do I need to write an extra function to read the property ID and parse it to the drupal-settings-json somehow?

  • Have a look for the GA script in the page source - does it use a JS variable to pass the ID to the web service, or is it already in a string? If the former, you can use the same var in your JS code; if the latter you'll need to write a bit of PHP code like you thought – Clive May 31 '17 at 16:48
  • the module writes the code directly in the head without passing the variable. but I hope there is still a way without writing custom functions. it seems to be a popular usecase (at least every german drupal website using analytics) and a standardized solution seems legit. – anonym-developer Jun 1 '17 at 10:36
  • There isn't a way to do it with writing code. That could be the module developer adding a new feature, of course, but the functionality doesn't exist, so someone needs to code it – Clive Jun 1 '17 at 10:40
  • I gues I know who needs to be this someone. tillthen, waiting for further comments / ideas. – anonym-developer Jun 1 '17 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.