Skip to content

Commit 54aa743

Browse files
fvschdonmckenna
andauthored
chore: cleanup GA code and more (#214)
* chore: remove now-unused VITE_GTAG_ID support * chore: remove compiled .vitepress/config.ts.mjs file --------- Co-authored-by: devon <[email protected]>
1 parent 98ab743 commit 54aa743

File tree

3 files changed

+5
-283
lines changed

3 files changed

+5
-283
lines changed

.vitepress/config.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -129,38 +129,14 @@ export default defineConfigWithTheme<ThemeConfig>({
129129
},
130130
});
131131

132-
function getAnalyticsTags({
133-
VITE_GTM_ID = '',
134-
VITE_GTAG_ID = '',
135-
}: NodeJS.ProcessEnv): HeadConfig[] {
136-
// Fail the build if we have a defined but malformed analytics id
137-
const idPattern = /^(G|GTM)-[A-Z\d]+$/;
138-
for (const [name, value] of Object.entries({ VITE_GTM_ID, VITE_GTAG_ID })) {
139-
if (value && !idPattern.test(value)) {
140-
throw new Error(`Invalid ${name} value: '${value}'`);
141-
}
142-
}
143-
132+
function getAnalyticsTags({ VITE_GTM_ID = '' }: NodeJS.ProcessEnv): HeadConfig[] {
133+
const idPattern = /^GTM-[A-Z\d]+$/;
144134
const tags: HeadConfig[] = [];
145135

146-
if (VITE_GTAG_ID) {
147-
const source = `
148-
window.dataLayer = window.dataLayer || [];
149-
function gtag(){ dataLayer.push(arguments) }
150-
gtag('js', new Date);
151-
gtag('config', '${VITE_GTAG_ID}', { anonymize_ip: true });
152-
`;
153-
tags.push(['script', {}, source]);
154-
if (!VITE_GTM_ID) {
155-
const url = `https://www.googletagmanager.com/gtag/js?id=${VITE_GTAG_ID}`;
156-
tags.push(['script', { async: '', src: url }]);
157-
}
158-
}
159-
160-
// We're migrating from gtag.js to gtm.js, but using both as we verify this change.
161-
// According to https://support.google.com/tagmanager/answer/6103696 this should be
162-
// inserted after any script declaring a dataLayer.
163136
if (VITE_GTM_ID) {
137+
if (!idPattern.test(VITE_GTM_ID)) {
138+
throw new Error(`Invalid VITE_GTM_ID value: '${VITE_GTM_ID}'`);
139+
}
164140
const source = `
165141
(function(w, d, s, l, i){
166142
w[l] = w[l] || [];

0 commit comments

Comments
 (0)