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