Skip to content

Commit 34fd9fe

Browse files
committed
refactor: add GTM
1 parent 9b6ab2f commit 34fd9fe

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

public/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,22 @@
3232
<meta name="msapplication-TileColor" content="#ffffff">
3333
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
3434
<meta name="theme-color" content="#ffffff">
35+
<!-- Google Tag Manager -->
36+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
37+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
38+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
39+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
40+
})(window,document,'script','dataLayer','GTM-KX4JH47');</script>
41+
<!-- End Google Tag Manager -->
3542
</head>
3643
<body>
3744
<noscript>
45+
<iframe
46+
src="https://www.googletagmanager.com/ns.html?id=GTM-KX4JH47"
47+
height="0"
48+
width="0"
49+
style="display: none; visibility: hidden"
50+
></iframe>
3851
<strong>We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
3952
</noscript>
4053
<div id="app"></div>

src/router/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,13 @@ const router = createRouter({
304304
},
305305
})
306306

307+
router.beforeResolve(() => {
308+
// Google Tag Manager
309+
window.dataLayer = window.dataLayer || []
310+
window.dataLayer.push({
311+
event: 'pageview',
312+
page_location: window.___location.href,
313+
})
314+
})
315+
307316
export default router

0 commit comments

Comments
 (0)