Skip to content

Commit 09e037d

Browse files
csarigozdaattali
authored andcommitted
Add Google Tag Manager Integration (daattali#157)
1 parent cef600c commit 09e037d

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ url-pretty: "MyWebsite.com" # eg. "deanattali.com/beautiful-jekyll"
9595
# Fill in your Google Analytics ID to track your website using GA
9696
#google_analytics: ""
9797

98+
# Google Tag Manager ID
99+
#gtm: ""
100+
98101
# Facebook App ID
99102
# fb_app_id: ""
100103

_includes/gtm_body.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% if site.gtm %}
2+
<!-- Google Tag Manager (noscript) -->
3+
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={{ site.gtm }}"
4+
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
5+
<!-- End Google Tag Manager (noscript) -->
6+
{% endif %}

_includes/gtm_head.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% if site.gtm %}
2+
<!-- Google Tag Manager -->
3+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
4+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
5+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
6+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
7+
})(window,document,'script','dataLayer','{{ site.gtm }}');</script>
8+
<!-- End Google Tag Manager -->
9+
{% endif %}

_includes/head.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
<link rel="alternate" type="application/rss+xml" title="{{ site.title }} {{ site.title-separator }} {{ site.description }}" href="{{ site.baseurl }}/feed.xml" />
1515

16+
{% include gtm_head.html %}
17+
1618
{% if layout.common-ext-css %}
1719
{% for css in layout.common-ext-css %}
1820
<link rel="stylesheet" href="{{ css }}" />

_layouts/base.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
{% include head.html %}
2121

2222
<body>
23+
24+
{% include gtm_body.html %}
2325

2426
{% include nav.html %}
2527

0 commit comments

Comments
 (0)