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 +18
-12
lines changed
Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -11,10 +11,6 @@ export default () => {
1111 return
1212 }
1313
14- const { ready } = config
15- const filename = config . debug . enabled ? 'analytics_debug' : 'analytics'
16- const resource = config . customResourceURL || `https://www.google-analytics.com/${ filename } .js`
17-
1814 if ( ! config . id ) {
1915 log ( 'Missing the "id" parameter. Add at least one tracking domain ID' )
2016 return
@@ -26,8 +22,14 @@ export default () => {
2622 ]
2723
2824 if ( shouldGaLoad ( ) ) {
25+ const domain = 'https://www.google-analytics.com'
26+ const filename = config . debug . enabled ? 'analytics_debug' : 'analytics'
27+ const resourcePromise = config . customResourceURL
28+ ? loadScript ( config . customResourceURL )
29+ : loadScript ( `${ domain } /${ filename } .js` , domain )
30+
2931 queue . push (
30- loadScript ( resource ) . catch ( ( ) => {
32+ resourcePromise . catch ( ( ) => {
3133 log ( 'An error occured! Please check your connection or disable your AD blocker' )
3234 } )
3335 )
@@ -55,7 +57,7 @@ export default () => {
5557 // Starts auto tracking
5658 autoTracking ( )
5759
58- ready ( )
60+ config . ready ( )
5961 } ) . catch ( error => {
6062 if ( ! config . debug . enabled ) {
6163 return
Original file line number Diff line number Diff line change @@ -6,20 +6,24 @@ export const log = message => {
66 console . warn ( `[vue-analytics] ${ message } ` )
77}
88
9- export function loadScript ( url ) {
9+ export function loadScript ( url , domain ) {
1010 return new Promise ( ( resolve , reject ) => {
11- var head = document . head || document . getElementsByTagName ( 'head' ) [ 0 ]
11+ const head = document . head || document . getElementsByTagName ( 'head' ) [ 0 ]
1212 const script = document . createElement ( 'script' )
13- const link = document . createElement ( 'link' )
1413
1514 script . async = true
1615 script . src = url
1716 script . charset = 'utf-8'
1817
19- link . href = url
20- link . rel = 'preconnect'
18+ if ( domain ) {
19+ const link = document . createElement ( 'link' )
20+
21+ link . href = domain
22+ link . rel = 'preconnect'
23+
24+ head . appendChild ( link )
25+ }
2126
22- head . appendChild ( link )
2327 head . appendChild ( script )
2428
2529 script . onload = resolve
You can’t perform that action at this time.
0 commit comments