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'
22import config , { update } from './config'
33import createTrackers from './create-trackers'
44import collectors from './collectors'
@@ -20,10 +20,11 @@ export default () => {
2020 )
2121 }
2222
23- if ( ! window . ga || ! disableScriptLoader ) {
23+ if ( shouldGaLoad ( ) && ( ! window . ga || ! disableScriptLoader ) ) {
2424 loadScript ( resource ) . catch ( ( ) => {
2525 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.`
2728 )
2829 } )
2930 }
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ export function loadScript (url) {
1111 script . charset = 'utf8'
1212
1313 head . appendChild ( script )
14-
14+
1515 script . onload = resolve
1616 script . onerror = reject
1717 } )
@@ -40,16 +40,21 @@ export function merge (obj, src) {
4040 return obj
4141}
4242
43- export function hasGoogleScript ( ) {
43+ export function hasScript ( ) {
4444 const scriptTags = Array . prototype . slice . call (
4545 document . getElementsByTagName ( 'script' )
4646 ) . filter ( script => {
47- return script . src . indexOf ( 'analytics' ) !== - 1
47+ return ( script . src . indexOf ( 'analytics' ) !== - 1 ) ||
48+ ( script . src . indexOf ( 'gtag' ) !== - 1 )
4849 } )
4950
5051 return scriptTags . length > 0
5152}
5253
54+ export function shouldGaLoad ( ) {
55+ return ! ( config . checkDuplicatedScript && hasScript ( ) )
56+ }
57+
5358export function getTracker ( tracker ) {
5459 return tracker . name || tracker . replace ( / - / gi, '' )
5560}
You can’t perform that action at this time.
0 commit comments