Skip to content

Commit

Permalink
feat: support crossOrigin option (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
aldarund authored Nov 10, 2020
1 parent cdb0c5c commit e843176
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default {
scriptId: 'gtm-script',
scriptDefer: false,
scriptURL: 'https://www.googletagmanager.com/gtm.js',
crossOrigin: false,

noscript: true,
noscriptId: 'gtm-noscript',
Expand Down
1 change: 1 addition & 0 deletions lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const defaults = {
scriptId: 'gtm-script',
scriptDefer: false,
scriptURL: 'https://www.googletagmanager.com/gtm.js',
crossOrigin: false,

noscript: true,
noscriptId: 'gtm-noscript',
Expand Down
2 changes: 1 addition & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = async function gtmModule (_options) {
.join('&')

// Compile scripts
const injectScript = `var f=d.getElementsByTagName(s)[0],j=d.createElement(s);j.${options.scriptDefer ? 'defer' : 'async'}=true;j.src='${options.scriptURL + '?id=\'+i' + (queryString ? (`+'&${queryString}` + '\'') : '')};f.parentNode.insertBefore(j,f)` // deps: d,s,i
const injectScript = `var f=d.getElementsByTagName(s)[0],j=d.createElement(s);${options.crossOrigin ? 'j.crossOrigin=\'' + options.crossOrigin + '\';' : ''}j.${options.scriptDefer ? 'defer' : 'async'}=true;j.src='${options.scriptURL + '?id=\'+i' + (queryString ? (`+'&${queryString}` + '\'') : '')};f.parentNode.insertBefore(j,f)` // deps: d,s,i

const doNotTrackScript = options.respectDoNotTrack ? 'if(w.doNotTrack||w[x][i])return;' : ''

Expand Down

0 comments on commit e843176

Please sign in to comment.