Skip to content

Commit

Permalink
feat: add anonymous Amplitude tracking for basic site analytics (#116)
Browse files Browse the repository at this point in the history
This PR adds Amplitude tracking for basic stats like page views, country
distribution, etc. We are instrumenting Amplitude with `identityStorage:
none` ala "anonymous" tracking which doesn't use cookies/storage for
identifying repeat users between sessions, otherwise we would need to
build a cookie compliance UI for EU folks which is more involved to do
with our current mdBook setup.
  • Loading branch information
williamrobertson13 authored Aug 22, 2024
1 parent 6f97afd commit d968abf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ indent_size = 2
max_line_length = 150

# Ignore paths
[{.git/**/*,LICENSE,**/Move.lock,mdbook-admonish.css}]
[{.git/**/*,LICENSE,**/Move.lock,mdbook-admonish.css,theme/**/*}]
charset = unset
end_of_line = unset
indent_size = unset
Expand Down
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ title = "Walrus"
[build]
build-dir = "build"


[output.html]
theme = "theme"
additional-css = ["./mdbook-admonish.css"]

[output.linkcheck]
Expand Down
8 changes: 8 additions & 0 deletions theme/head.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script type="text/javascript">
// Hacky check to only load Amplitude in production since we don't have environments:
const localAddresses = ['localhost', '127.0.0.1', '[::1]'];
if (localAddresses.indexOf(document.location.hostname) === -1) {
!function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},o=function(e,t,r){e._q.push({name:t,args:Array.prototype.slice.call(r,0)})},i=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))};o(e,t,Array.prototype.slice.call(arguments))}},a=function(e){for(var t=0;t<g.length;t++)i(e,g[t],!1);for(var r=0;r<m.length;r++)i(e,m[r],!0)};r.invoked=!0;var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-pY2pkwHaLM/6UIseFHVU3hOKr6oAvhLcdYkoRZyaMDWLjpM6B7nTxtOdE823WAOQ",c.crossOrigin="anonymous",c.async=!0,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.11.0-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var u=t.getElementsByTagName("script")[0];u.parentNode.insertBefore(c,u);for(var p=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<l.length;d++)n(p,l[d]);r.Identify=p;for(var f=function(){return this._q=[],this},v=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],y=0;y<v.length;y++)n(f,v[y]);r.Revenue=f;var g=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],m=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];a(r),r.createInstance=function(e){return r._iq[e]={_q:[]},a(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
amplitude.init('f60df2d0d709d50faa2ffda153a84bc0', { identityStorage:'none', defaultTracking: true });
}
</script>

0 comments on commit d968abf

Please sign in to comment.