@dpgradio/creative 7.1.0 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dpgradio/creative",
3
- "version": "7.1.0",
3
+ "version": "7.1.1",
4
4
  "description": "Support package for standalone Javascript applications",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -10,8 +10,28 @@ class DataLayer {
10
10
  this.userInformation = {}
11
11
  }
12
12
 
13
- initialize(gtmId = 'GTM-TW99VZN') {
14
- loadScript(`https://www.googletagmanager.com/gtm.js?id=${gtmId}`)
13
+ /**
14
+ * @param {Object} parameters The parameters object.
15
+ * @param {string} [parameters.gtmId] The GTM ID - Defaults to our default GTM tag
16
+ * @param {string} [parameters.nonce] The nonce value for the script tag (Used for CSP).
17
+ */
18
+ initialize(parameters) {
19
+ // Backwards compatability
20
+ if (typeof parameters === 'string') {
21
+ parameters = { gtmId: parameters }
22
+
23
+ // Deprecation warning in development
24
+ if (process.env.NODE_ENV === 'development') {
25
+ console.warn(
26
+ '@dpgmedia/creative',
27
+ 'DEPRECATION WARNING: new Datalayer(gtmId) is deprecated, please use new Datalayer({ gtmId }) instead.'
28
+ )
29
+ }
30
+ }
31
+
32
+ const { gtmId = 'GTM-TW99VZN', nonce } = parameters || {}
33
+
34
+ loadScript(`https://www.googletagmanager.com/gtm.js?id=${gtmId}`, { nonce })
15
35
 
16
36
  this.pushGtmStart()
17
37
  this.pushUserWhenAuthenticated()
@@ -18,10 +18,10 @@ class Configuration {
18
18
  /**
19
19
  * Retrieve the configuration for the current hostname or present query parameter and the given app (optional).
20
20
  */
21
- async retrieveConfigForDetectedStation(appId = null) {
21
+ async retrieveConfigForDetectedStation(appId = null, { parameterName = 'stationId' } = {}) {
22
22
  const parameters = new URLSearchParams(window.location.search)
23
- if (parameters.has('stationId')) {
24
- return this.retrieveConfigForStation(parameters.get('stationId'), appId)
23
+ if (parameters.has(parameterName)) {
24
+ return this.retrieveConfigForStation(parameters.get(parameterName), appId)
25
25
  }
26
26
  return this.retrieveConfigByHostname(appId)
27
27
  }
@@ -15,11 +15,14 @@ class Privacy {
15
15
  * @param {string} privacyManagerId e.g. '148844'
16
16
  * @param {string} websiteUrl e.g. 'https://qmusic.nl'
17
17
  * @param {string} cmpCname e.g. 'https://cmp.qmusic.nl'
18
+ * @param {Object} options Additional options.
19
+ * @param {string} [options.nonce] The nonce value for the script tag (Used for CSP).
18
20
  */
19
21
  initialize(
20
22
  privacyManagerId = config('privacy_manager_id'),
21
23
  websiteUrl = config('website_url'),
22
- cmpCname = config('cmp_cname')
24
+ cmpCname = config('cmp_cname'),
25
+ { nonce = undefined } = {}
23
26
  ) {
24
27
  window.cmpProperties = {
25
28
  privacyManagerId,
@@ -28,7 +31,7 @@ class Privacy {
28
31
  language: 'nl',
29
32
  }
30
33
 
31
- loadScript('https://myprivacy-static.dpgmedia.net/consent.js')
34
+ loadScript('https://myprivacy-static.dpgmedia.net/consent.js', { nonce })
32
35
 
33
36
  this.requestConsentInformation()
34
37
  }
@@ -1,12 +1,15 @@
1
1
  // From: https://github.com/medialaan/radio-radioplayer-frontend/blob/develop/src/general/utils/loadScript.js
2
2
  // TODO: Refactor
3
3
 
4
- export default function loadScript(url, { timeout = undefined } = {}) {
4
+ export default function loadScript(url, { timeout = undefined, nonce = undefined } = {}) {
5
5
  return new Promise((resolve, reject) => {
6
6
  let script = document.createElement('script')
7
7
  const firstScript = document.getElementsByTagName('script')[0]
8
8
  script.async = true
9
9
  script.defer = true
10
+ if (nonce) {
11
+ script.nonce = nonce
12
+ }
10
13
 
11
14
  const loadScriptTimeout = timeout ? setTimeout(() => reject(`Loading script [${url}] blocked.`), timeout) : null
12
15