Skip to content

Commit

Permalink
Add Google Tag Manager analytics setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
GUI committed Mar 13, 2024
1 parent 87b2970 commit 7a7de96
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
16 changes: 7 additions & 9 deletions source/layouts/_analytics.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '<%= ENV["GOOGLE_ANALYTICS_TRACKING_ID"] %>', 'auto');
ga('send', 'pageview');
</script>
<!-- Google Tag Manager -->
<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-KG7PVKB');</script>
<!-- End Google Tag Manager -->
4 changes: 4 additions & 0 deletions source/layouts/_noscript_analytics.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src=https://www.googletagmanager.com/ns.html?id=GTM-KG7PVKB
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
3 changes: 2 additions & 1 deletion source/layouts/blank.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="en-US" class="no-js">
<head>
<%= partial("layouts/analytics") %>
<title>
<%= current_page.data.title %> | Your API Site Name
</title>
Expand All @@ -9,9 +10,9 @@
<meta content="en" name="language">

<%= stylesheet_link_tag("all") %>
<%= partial("layouts/analytics") %>
</head>
<body class="blank <%= page_classes %>">
<%= partial("layouts/noscript_analytics") %>
<%= yield %>
</body>
</html>
3 changes: 2 additions & 1 deletion source/layouts/layout.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<%= partial("layouts/analytics") %>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down Expand Up @@ -28,9 +29,9 @@
<%= javascript_include_tag("shared") %>
<%= javascript_include_tag("all") %>
<%= partial("layouts/analytics") %>
</head>
<body class="<%= page_classes %>">
<%= partial("layouts/noscript_analytics") %>
<%= partial("layouts/header") %>
<%= yield %>
<%= partial("layouts/edit_me") %>
Expand Down

0 comments on commit 7a7de96

Please sign in to comment.