Skip to content

Commit

Permalink
Merge pull request #111 from petridishdev/analytics
Browse files Browse the repository at this point in the history
Adds snowplow browser tracker
  • Loading branch information
WadeBarnes authored Dec 30, 2021
2 parents 292696a + 887374a commit 281f127
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 31 deletions.
148 changes: 145 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"i18n:report": "vue-cli-service i18n:report --src \"./src/**/*.?(js|vue)\" --locales \"./src/i18n/**/*.json\""
},
"dependencies": {
"@snowplow/browser-tracker": "^3.1.6",
"axios": "^0.21.4",
"core-js": "^3.17.2",
"lodash-es": "^4.17.21",
Expand Down
28 changes: 0 additions & 28 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,6 @@
<meta name="description" content="A public directory of organizations registered in BC">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
<script type="text/javascript">
// <!-- Snowplow starts plowing - Standalone vE.2.14.0 -->
; (function (p, l, o, w, i, n, g) {
if (!p[i]) {
p.GlobalSnowplowNamespace = p.GlobalSnowplowNamespace || [];
p.GlobalSnowplowNamespace.push(i); p[i] = function () {
(p[i].q = p[i].q || []).push(arguments)
}; p[i].q = p[i].q || []; n = l.createElement(o); g = l.getElementsByTagName(o)[0]; n.async = 1;
n.src = w; g.parentNode.insertBefore(n, g)
}
}(window, document, "script", "https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js", "snowplow"));
var collector = 'spt.apps.gov.bc.ca';
window.snowplow('newTracker', 'rt', collector, {
appId: "Snowplow_standalone",
cookieLifetime: 86400 * 548,
platform: 'web',
post: true,
forceSecureTracker: true,
contexts: {
webPage: true,
performanceTiming: true
}
});
window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds
window.snowplow('enableLinkClickTracking');
window.snowplow('trackPageView');
// <!-- Snowplow stops plowing -->
</script>
</head>
<body>
<noscript>
Expand Down
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { dateFilter } from "@/filters/date.filter";
import { claimFormat } from "@/filters/claim.filter";
import docs from "@/assets/docs.json";
import { defaultDoc, processDocRoute } from "./utils/doc";
import { newTracker, trackPageView } from "@snowplow/browser-tracker";

Vue.config.productionTip = false;
Vue.filter("formatDate", dateFilter);
Expand All @@ -30,6 +31,13 @@ async function init() {
},
render: (h) => h(App),
}).$mount("#app");

// Snowplow tracking
newTracker("OrgBookClient", "spt.apps.gov.bc.ca", {
appId: "#app",
plugins: [],
});
trackPageView();
}

init();

0 comments on commit 281f127

Please sign in to comment.