Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
{{ end -}}

<script src='{{ "js/index.js" | relURL }}' defer></script>
{{ partial "segment.html" . }}
{{ if .Params.math }}
{{ partial "mathjax.html" }}
{{ end }}
Expand Down
10 changes: 10 additions & 0 deletions layouts/partials/segment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
!function(){var i="analytics",analytics=window[i]=window[i]||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","screen","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware","register"];analytics.factory=function(e){return function(){if(window[i].initialized)return window[i][e].apply(window[i],arguments);var n=Array.prototype.slice.call(arguments);if(["track","screen","alias","group","page","identify"].indexOf(e)>-1){var c=document.querySelector("link[rel='canonical']");n.push({__t:"bpc",c:c&&c.getAttribute("href")||void 0,p:location.pathname,u:location.href,s:location.search,t:document.title,r:document.referrer})}n.unshift(e);analytics.push(n);return analytics}};for(var n=0;n<analytics.methods.length;n++){var key=analytics.methods[n];analytics[key]=analytics.factory(key)}analytics.load=function(key,n){var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.setAttribute("data-global-segment-analytics-key",i);t.src="https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js";var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(t,r);analytics._loadOptions=n};analytics._writeKey="WRrz9T87YdiSbmMaU8rm2JAq7EFKp5H4";;analytics.SNIPPET_VERSION="5.2.0";
analytics.load("WRrz9T87YdiSbmMaU8rm2JAq7EFKp5H4");
}}();
</script>
<script>
analytics.track('PageViewed', {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super familiar with the syntax, will this function be called on every page that loaded?
For example:
Going to page X will fire the PageViewed page_name=X and going to page Y will fire with page_name=Y?

page_name: name || (typeof window !== 'undefined' ? window.location.pathname : undefined)
});
</script>