File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -123,7 +123,11 @@ Vue.use(VueMatomo, {
123123 // return null
124124 // }
125125 // }
126- trackSiteSearch: false
126+ trackSiteSearch: false ,
127+
128+ // Set this to include crossorigin attribute on the matomo script import
129+ // Default: undefined, possible values : 'anonymous', 'use-credentials'
130+ crossOrigin: undefined ,
127131});
128132
129133// Now you can access piwik api in components through
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ const defaultOptions = {
1616 userId : undefined ,
1717 cookieDomain : undefined ,
1818 domains : undefined ,
19- preInitActions : [ ]
19+ preInitActions : [ ] ,
20+ crossOrigin : undefined
2021}
2122
2223export const matomoKey = 'Matomo'
@@ -180,7 +181,7 @@ export default function install (Vue, setupOptions = {}) {
180181
181182 options . preInitActions . forEach ( ( action ) => window . _paq . push ( action ) )
182183
183- loadScript ( trackerScript )
184+ loadScript ( trackerScript , options . crossOrigin )
184185 . then ( ( ) => piwikExists ( ) )
185186 . then ( ( ) => initMatomo ( Vue , options ) )
186187 . catch ( ( error ) => {
Original file line number Diff line number Diff line change @@ -2,13 +2,17 @@ export function getMatomo () {
22 return window . Piwik . getAsyncTracker ( )
33}
44
5- export function loadScript ( trackerScript ) {
5+ export function loadScript ( trackerScript , crossOrigin = undefined ) {
66 return new Promise ( ( resolve , reject ) => {
77 const script = document . createElement ( 'script' )
88 script . async = true
99 script . defer = true
1010 script . src = trackerScript
1111
12+ if ( crossOrigin && [ 'anonymous' , 'use-credentials' ] . includes ( crossOrigin ) ) {
13+ script . crossOrigin = crossOrigin
14+ }
15+
1216 const head = document . head || document . getElementsByTagName ( 'head' ) [ 0 ]
1317 head . appendChild ( script )
1418
You can’t perform that action at this time.
0 commit comments