Skip to content

Commit

Permalink
Merge pull request #79 from pages-themes/head-custom
Browse files Browse the repository at this point in the history
Add Google Analytics to head-custom.html to allow easier customization of the GA code
  • Loading branch information
parkr authored Jul 26, 2021
2 parents 042c290 + fd3f6c1 commit 457c378
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
10 changes: 10 additions & 0 deletions _includes/head-custom-google-analytics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% if site.google_analytics %}
<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', '{{ site.google_analytics }}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}
7 changes: 5 additions & 2 deletions _includes/head-custom.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<!-- start custom head snippets, customize with your own _includes/head-custom.html file -->

<!-- Setup theme-color. -->
<!-- Setup theme-color -->
{% include head-custom-theme-colors.html %}

<!-- You can set your favicon here. -->
<!-- Setup Google Analytics -->
{% include head-custom-google-analytics.html %}

<!-- You can set your favicon here -->
<!-- link rel="shortcut icon" type="image/x-icon" href="{{ '/favicon.ico' | relative_url }}" -->

<!-- end custom head snippets -->
11 changes: 0 additions & 11 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,5 @@ <h2>{{ site.description | default: site.github.project_tagline }}</h2>
{{ content }}
</section>
</div>

{% if site.google_analytics %}
<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', '{{ site.google_analytics }}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}
</body>
</html>

0 comments on commit 457c378

Please sign in to comment.