-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to Google Analytics 4, GA4 as UA is deprecated
Main repo that this is forked from does not appear to be maintained. Referenced mmistakes/so-simple-theme#429
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% comment %} | ||
Old style Google analytics uses codes of the form UA-XXXXXXXX. The new Google Analytics 4 uses codes of the form G-XXXXXXX. Each has different javascript. | ||
{% endcomment %} | ||
|
||
{%- if site.google_analytics contains 'UA-' -%} | ||
<script> | ||
if(!(window.doNotTrack === "1" || navigator.doNotTrack === "1" || navigator.doNotTrack === "yes" || navigator.msDoNotTrack === "1")) { | ||
(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','https://www.google-analytics.com/analytics.js','ga'); | ||
ga('create', '{{ site.google_analytics }}', 'auto'); | ||
ga('send', 'pageview'); | ||
} | ||
</script> | ||
{%- else %} | ||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', '{{ site.google_analytics }}'); | ||
</script> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{%- if site.footer_scripts -%} | ||
{%- for script in site.footer_scripts -%} | ||
{%- if script contains "://" -%} | ||
{%- capture script_path %}{{ script }}{% endcapture -%} | ||
{%- else -%} | ||
{%- capture script_path %}{{ script | absolute_url }}{% endcapture -%} | ||
{%- endif -%} | ||
<script src="{{ script_path }}"></script> | ||
{%- endfor -%} | ||
{%- else -%} | ||
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> | ||
<script src="{{ '/assets/js/main.min.js' | relative_url }}"></script> | ||
<script src="https://use.fontawesome.com/releases/v5.0.12/js/all.js"></script> | ||
{%- endif -%} | ||
|
||
{%- if jekyll.environment == 'production' and site.google_analytics -%} | ||
<!-- leewc: Override google-analytics from main theme given main theme is not maintained --> | ||
{% include google-analytics-custom.html %} | ||
{%- endif %} | ||
|
||
{% if site.mathjax == true or site.mathjax.enable == true %} | ||
<!-- MathJax --> | ||
{% capture mathjaxjs %}https://cdn.jsdelivr.net/npm/mathjax@3/es5/{{ site.mathjax.combo | default: "tex-svg" }}.js{% endcapture %} | ||
<script> | ||
// http://docs.mathjax.org/en/latest/upgrading/v2.html | ||
MathJax = { | ||
tex: { | ||
tags: "{{ site.mathjax.tags | default: 'ams' }}" // eq numbering options: none, ams, all | ||
}, | ||
options: { | ||
renderActions: { | ||
// for mathjax 3, handle <script "math/tex"> blocks inserted by kramdown | ||
find: [10, function (doc) { | ||
for (const node of document.querySelectorAll('script[type^="math/tex"]')) { | ||
const display = !!node.type.match(/; *mode=display/); | ||
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display); | ||
const text = document.createTextNode(''); | ||
node.parentNode.replaceChild(text, node); | ||
math.start = {node: text, delim: '', n: 0}; | ||
math.end = {node: text, delim: '', n: 0}; | ||
doc.math.push(math); | ||
} | ||
}, ''] | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<script type="text/javascript" id="MathJax-script" async src="{{ mathjaxjs }}"></script> | ||
{% endif %} | ||
|
||
{%- if page.layout == "search" -%} | ||
{% include lunr-search-scripts.html %} | ||
{%- endif -%} |