Skip to content

Commit

Permalink
Merge pull request #323 from IgniteUI/hPopov/ga-spa-tracking
Browse files Browse the repository at this point in the history
Add GA tracking for SPA
  • Loading branch information
Hristo Popov authored Jun 10, 2021
2 parents f3ceb07 + 228a689 commit c36f403
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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>

0 comments on commit c36f403

Please sign in to comment.