-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
Copy pathgtag.test.js
84 lines (67 loc) · 2.12 KB
/
gtag.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import docsifyInit from '../helpers/docsify-init.js';
import { test, expect } from './fixtures/docsify-init-fixture.js';
const gtagList = [
'AW-YYYYYY', // Google Ads
'DC-ZZZZZZ', // Floodlight
'G-XXXXXX', // Google Analytics 4 (GA4)
'UA-XXXXXX', // Google Universal Analytics (GA3)
];
test.describe('Gtag Plugin Tests', () => {
// page request listened, print collect url
function pageRequestListened(page) {
page.on('request', request => {
if (request.url().indexOf('www.google-analytics.com') !== -1) {
// console.log(request.url());
}
});
page.on('response', response => {
const request = response.request();
// googleads.g.doubleclick.net
// www.google-analytics.com
// www.googletagmanager.com
const reg =
/googleads\.g\.doubleclick\.net|www\.google-analytics\.com|www\.googletagmanager\.com/g;
if (request.url().match(reg)) {
// console.log(request.url(), response.status());
}
});
}
test('single gtag', async ({ page }) => {
pageRequestListened(page);
const docsifyInitConfig = {
config: {
gtag: gtagList[0],
},
scriptURLs: ['/dist/plugins/gtag.js'],
styleURLs: ['/dist/themes/core.css'],
};
await docsifyInit({
...docsifyInitConfig,
});
const $docsify = await page.evaluate(() => window.$docsify);
// Verify config options
expect(typeof $docsify).toEqual('object');
// console.log($docsify.gtag, $docsify.gtag === '');
// Tests
expect($docsify.gtag).not.toEqual('');
});
test('multi gtag', async ({ page }) => {
pageRequestListened(page);
const docsifyInitConfig = {
config: {
gtag: gtagList,
},
scriptURLs: ['/dist/plugins/gtag.js'],
styleURLs: ['/dist/themes/core.css'],
};
await docsifyInit({
...docsifyInitConfig,
});
const $docsify = await page.evaluate(() => window.$docsify);
// Verify config options
expect(typeof $docsify).toEqual('object');
// console.log($docsify.gtag, $docsify.gtag === '');
// Tests
expect($docsify.gtag).not.toEqual('');
});
});