Skip to content

Commit

Permalink
refactor: Refactor Google Analytics and Google Tag Manager code in as…
Browse files Browse the repository at this point in the history
…ync.html (analytics.js -> gtag.js only)

refactor: google_analytics_tracking_id -> google_analytics_measurement_id
  • Loading branch information
rcmdnk committed Sep 17, 2023
1 parent 6641608 commit 96095e4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
5 changes: 4 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ disqus_short_name:
disqus_show_comment_count: false

# Google Analytics
google_analytics_tracking_id:
google_analytics_measurement_id:

# Google Tag Manager
google_tag_manager_id:

# Facebook Like
facebook_like: false
Expand Down
13 changes: 10 additions & 3 deletions patches/_config.yml.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/_config.yml b/_config.yml
index c1d56f4..26d3572 100644
index c1d56f4..b260ef1 100644
--- a/_config.yml
+++ b/_config.yml
@@ -2,24 +2,57 @@
Expand Down Expand Up @@ -126,7 +126,7 @@ index c1d56f4..26d3572 100644

# Each layout uses the default asides, but they can have their own asides instead. Simply uncomment the lines below
# and add an array with the asides you want to use.
@@ -59,36 +112,104 @@ default_asides: [asides/recent_posts.html, asides/github.html, asides/delicious.
@@ -59,43 +112,283 @@ default_asides: [asides/recent_posts.html, asides/github.html, asides/delicious.
# post_asides:
# page_asides:

Expand Down Expand Up @@ -242,7 +242,14 @@ index c1d56f4..26d3572 100644

# Disqus Comments
disqus_short_name:
@@ -99,3 +220,172 @@ google_analytics_tracking_id:
disqus_show_comment_count: false

# Google Analytics
-google_analytics_tracking_id:
+google_analytics_measurement_id:
+
+# Google Tag Manager
+google_tag_manager_id:

# Facebook Like
facebook_like: false
Expand Down
21 changes: 5 additions & 16 deletions source/_includes/async.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,14 @@
{% endcomment %}
})(document);
</script>
{% if site.google_analytics_tracking_id %}
<script>
window.GoogleAnalyticsObject = 'ga';
if (!('ga' in window)){
ga = function(){
ga.q.push(arguments);
};
}
ga.l = (new Date()).getTime();
ga.q = [['create', '{{site.google_analytics_tracking_id}}', 'auto'], ['send', 'pageview'], ['require', 'linkid', 'linkid.js']];
</script>
<script src="//www.google-analytics.com/analytics.js" async defer></script>

<script src="https://www.googletagmanager.com/gtag/js?id={{site.google_analytics_tracking_id}}" async defer></script>
{% if site.google_analytics_measurement_id %}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{site.google_analytics_measurement_id}}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{site.google_analytics_tracking_id}}');
gtag('config', '{{site.google_analytics_measurement_id}}');
</script>
{% endif %}
{% if site.google_tag_manager_id %}
Expand All @@ -48,7 +37,7 @@
{% endif %}
{% if site.google_translate_layout and page.translate != false %}
<script>
{% capture analytics %}{% if site.google_analytics_tracking_id %}, gaTrack: true, gaId: '{{site.google_analytics_tracking_id}}'{% endif %}{% endcapture %}
{% capture analytics %}{% if site.google_analytics_measurement_id %}, gaTrack: true, gaId: '{{site.google_analytics_measurement_id}}'{% endif %}{% endcapture %}
{% capture layout %}{% if site.google_translate_layout == 'SIMPLE' %}InlineLayout.SIMPLE{% else %}FloatPosition.{{site.google_translate_layout}}{% endif %}{% endcapture %}
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: '{{site.google_translate_lang}}', layout: google.translate.TranslateElement.{{layout}}, autoDisplay: false, multilanguagePage: true{{analytics}}}, 'google_translate_element');
Expand Down

0 comments on commit 96095e4

Please sign in to comment.