File tree Expand file tree Collapse file tree 3 files changed +9
-19
lines changed Expand file tree Collapse file tree 3 files changed +9
-19
lines changed Original file line number Diff line number Diff line change @@ -75,11 +75,12 @@ Install the plugin and configure the track id.
7575
7676``` html
7777<script >
78+ // Single ID
7879 window .$docsify = {
7980 ga: ' UA-XXXXX-Y' ,
8081 };
8182
82- // or multi gtag, first tag at the beginning of G- from the array is global site gtag, each page should have only one global site tag instance.
83+ // Multiple IDs
8384 window .$docsify = {
8485 ga: [
8586 ' G-XXXXXXXX' , // Google Analytics 4 (GA4)
Original file line number Diff line number Diff line change 11/* eslint-disable no-console */
22// From https://github.com/egoist/vue-ga/blob/master/src/index.js
33
4- // prefix of global site tag
5- const GLOBAL_SITE_TAG_PREFIX = 'G-' ;
6-
74function appendScript ( id ) {
85 const script = document . createElement ( 'script' ) ;
96 script . async = true ;
@@ -34,24 +31,15 @@ function initAdditionalTag(id) {
3431
3532function init ( ids ) {
3633 if ( Array . isArray ( ids ) ) {
37- // default get the first id
38- let globalSiteTag = ids [ 0 ] ;
39- let globalSiteTagArr = ids . filter (
40- id => id . indexOf ( GLOBAL_SITE_TAG_PREFIX ) === 0
41- ) ;
42- if ( globalSiteTagArr . length !== 0 ) {
43- globalSiteTag = globalSiteTagArr [ 0 ] ;
44- }
45-
46- // initialized global site tag id
47- initGlobalSiteTag ( globalSiteTag ) ;
34+ // set the first id to be a global site tag
35+ initGlobalSiteTag ( ids [ 0 ] ) ;
4836
4937 // the rest ids
50- ids
51- . filter ( id => id !== globalSiteTag )
52- . forEach ( ( id , index ) => {
38+ ids . forEach ( ( id , index ) => {
39+ if ( index > 0 ) {
5340 initAdditionalTag ( id ) ;
54- } ) ;
41+ }
42+ } ) ;
5543 } else {
5644 initGlobalSiteTag ( ids ) ;
5745 }
Original file line number Diff line number Diff line change 11// Modules, constants, and variables
2+ // npm run test:e2e ga.test.js
23// -----------------------------------------------------------------------------
34const docsifyInit = require ( '../helpers/docsify-init' ) ;
45const { test, expect } = require ( './fixtures/docsify-init-fixture' ) ;
You can’t perform that action at this time.
0 commit comments