Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GA tracking for SPA #323

Merged
merged 1 commit into from
Jun 10, 2021
Merged
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
7 changes: 7 additions & 0 deletions src/app/services/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ export class Router {
if(data) {
let parsedDOM = $("<div>").append($.parseHTML(data));
meta.configureMetadata(parsedDOM);

(window as any).dataLayer.push({
'event': 'trackSPAPageview',
'pagePath': location.pathname,
'pageTitle': window.document.title
});

await this.defaultHandler(options.adjustTocScrollPosition ?? true, options.scrollPosition ?? 0);

if(options.navigationPostProcess)
Expand Down
3 changes: 2 additions & 1 deletion src/app/services/search/lunr-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ const createHitBlock = (hit: ISearchItem): JQuery<HTMLElement> => {
$itemTitleNode.append($hitAnchor);

if(util.removeHTMLExtensionFromUrl) {
$itemBriefNode.text($itemBriefNode.text().replace(".html", ""));
$itemHrefNode.text($itemHrefNode.text().replace(".html", ""));
}

$hitBlock
.append($itemTitleNode)
.append($itemHrefNode)
Expand Down
9 changes: 8 additions & 1 deletion template/partials/head.tmpl.partial
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ full license information.}}
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{environment:GTMContainerId}');</script>
})(window,document,'script','dataLayer','{environment:GTMContainerId}');
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'trackSPAPageview',
'pagePath': location.pathname,
'pageTitle': document.title
});
</script>
<!-- End Google Tag Manager -->
</head>