Skip to content

Commit 0727c99

Browse files
committed
Add google analytics header.
1 parent 82719a1 commit 0727c99

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

playground/src/app.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,32 @@ fn diagram_only_init() -> bool {
6060
}
6161
}
6262

63+
#[component]
64+
pub fn GoogleAnalyticsHeader() -> impl IntoView {
65+
view! {
66+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QWXYFJ1NED"></script>
67+
<script>
68+
"\
69+
window.dataLayer = window.dataLayer || [];\n\
70+
function gtag(){dataLayer.push(arguments);}\n\
71+
gtag('js', new Date());\n\
72+
gtag('config', 'G-QWXYFJ1NED');\n\
73+
"
74+
</script>
75+
}
76+
}
77+
6378
#[component]
6479
pub fn GoogleTagManagerHeader() -> impl IntoView {
6580
view! {
6681
<script>
67-
"(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\
68-
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\
69-
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\
70-
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\
71-
})(window,document,'script','dataLayer','GTM-W2485ZNP');"
82+
"\
83+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n\
84+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n\
85+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n\
86+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n\
87+
})(window,document,'script','dataLayer','GTM-W2485ZNP');\n\
88+
"
7289
</script>
7390
}
7491
}
@@ -104,6 +121,7 @@ pub fn App() -> impl IntoView {
104121
// through client side routing.
105122
if site_prefix.is_empty() {
106123
view! {
124+
<GoogleAnalyticsHeader />
107125
<GoogleTagManagerHeader />
108126

109127
// injects a stylesheet into the document <head>

0 commit comments

Comments
 (0)