Skip to content

Commit

Permalink
Add google analytics header.
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 committed Aug 7, 2024
1 parent 82719a1 commit 0727c99
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions playground/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,32 @@ fn diagram_only_init() -> bool {
}
}

#[component]
pub fn GoogleAnalyticsHeader() -> impl IntoView {
view! {
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QWXYFJ1NED"></script>
<script>
"\
window.dataLayer = window.dataLayer || [];\n\
function gtag(){dataLayer.push(arguments);}\n\
gtag('js', new Date());\n\
gtag('config', 'G-QWXYFJ1NED');\n\

Check warning on line 72 in playground/src/app.rs

View workflow job for this annotation

GitHub Actions / Docs and Spell Check

"NED" should be "NEED" or "END".
"
</script>
}
}

#[component]
pub fn GoogleTagManagerHeader() -> impl IntoView {
view! {
<script>
"(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\
})(window,document,'script','dataLayer','GTM-W2485ZNP');"
"\
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n\
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n\
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n\
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n\
})(window,document,'script','dataLayer','GTM-W2485ZNP');\n\
"
</script>
}
}
Expand Down Expand Up @@ -104,6 +121,7 @@ pub fn App() -> impl IntoView {
// through client side routing.
if site_prefix.is_empty() {
view! {
<GoogleAnalyticsHeader />
<GoogleTagManagerHeader />

// injects a stylesheet into the document <head>
Expand Down

0 comments on commit 0727c99

Please sign in to comment.