Skip to content

Commit a3b6aea

Browse files
committed
feat: optimize Google Analytics tracking with idle callbacks and beacon transport
1 parent 82010a9 commit a3b6aea

File tree

5 files changed

+210
-116
lines changed

5 files changed

+210
-116
lines changed

Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
# Speedier defaults and robust targets
22
.PHONY: start deps clean build serve
33

4-
NPM_FLAGS ?= --prefer-offline --no-audit --no-fund
5-
64
start:
75
npm run develop
86

97
deps:
10-
@if [ -d node_modules ]; then \
11-
npm i $(NPM_FLAGS); \
12-
else \
13-
npm ci $(NPM_FLAGS); \
14-
fi
8+
npm i
159

1610
clean:
1711
rm -rf node_modules

gatsby-browser.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const onRouteUpdate = () => {
2+
const send = () => window.gtag && window.gtag('event', 'page_view');
3+
if ('requestIdleCallback' in window) {
4+
requestIdleCallback(send, { timeout: 2000 });
5+
} else {
6+
setTimeout(send, 2000);
7+
}
8+
};

gatsby-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module.exports = {
1919
],
2020
gtagConfig: {
2121
anonymize_ip: true,
22+
send_page_view: false,
23+
transport_type: 'beacon',
2224
},
2325
pluginConfig: {
2426
head: false,

optimize-hero.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)