How can my JavaScript-function access the Web Property ID from the Google Analytics module? 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. 

&lt;script type="application/json" data-drupal-selector="drupal-settings-json"&gt;{"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?
The most popular Google Analytics module (google_analytics) relies on generating inline JavaScript snippets for initializing tracking, which can make altering its behaviour difficult - likely requiring patching the module.

Googalytics is a more flexible alternative for Google Analytics in Drupal 8


drupalSettings is used to pass data to the front end.  This removes the use of inline JS, also making  the module compitible with Content Security Policy.
The data structure isn't intended to be modified on the front-end by JS, but hopefully the improved control possible in the back-end makes it unnecessary.
There's an open issue (with a patch currently needing feedback) for integrating  with the EU Cookie Compliance module.  If this matches your use case you may not need to write any custom code, otherwise it may provide a template for how to override the module's JS library for your needs.