This repository was archived by the owner on Mar 21, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 1
- import { loadScript } from './helpers'
1
+ import { loadScript , shouldGaLoad } from './helpers'
2
2
import config , { update } from './config'
3
3
import createTrackers from './create-trackers'
4
4
import collectors from './collectors'
@@ -20,10 +20,11 @@ export default () => {
20
20
)
21
21
}
22
22
23
- if ( ! window . ga || ! disableScriptLoader ) {
23
+ if ( shouldGaLoad ( ) && ( ! window . ga || ! disableScriptLoader ) ) {
24
24
loadScript ( resource ) . catch ( ( ) => {
25
25
console . error (
26
- `[vue-analytics] An error occured trying to load ${ resource } . Please check your connection.`
26
+ `[vue-analytics] An error occured trying to load ${ resource } . Please check your connection ` +
27
+ `or if you have any Google Analytics blocker installed in your browser.`
27
28
)
28
29
} )
29
30
}
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ export function loadScript (url) {
11
11
script . charset = 'utf8'
12
12
13
13
head . appendChild ( script )
14
-
14
+
15
15
script . onload = resolve
16
16
script . onerror = reject
17
17
} )
@@ -40,16 +40,21 @@ export function merge (obj, src) {
40
40
return obj
41
41
}
42
42
43
- export function hasGoogleScript ( ) {
43
+ export function hasScript ( ) {
44
44
const scriptTags = Array . prototype . slice . call (
45
45
document . getElementsByTagName ( 'script' )
46
46
) . filter ( script => {
47
- return script . src . indexOf ( 'analytics' ) !== - 1
47
+ return ( script . src . indexOf ( 'analytics' ) !== - 1 ) ||
48
+ ( script . src . indexOf ( 'gtag' ) !== - 1 )
48
49
} )
49
50
50
51
return scriptTags . length > 0
51
52
}
52
53
54
+ export function shouldGaLoad ( ) {
55
+ return ! ( config . checkDuplicatedScript && hasScript ( ) )
56
+ }
57
+
53
58
export function getTracker ( tracker ) {
54
59
return tracker . name || tracker . replace ( / - / gi, '' )
55
60
}
You can’t perform that action at this time.
0 commit comments