Skip to content

Commit

Permalink
Merge pull request #3 from bouvet-apps/bugfix/site-not-mounted-on-dom…
Browse files Browse the repository at this point in the history
…ain-root

Fix bug with matomo only working on site mounted on domain root
  • Loading branch information
vi-h authored Feb 24, 2023
2 parents f43fdc3 + 85f41e5 commit 2b50a55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ displayName = Matomo Analytics App
vendor = Bouvet Norge AS
vendorUrl = https://www.bouvet.no
xpVersion = 7.5.0
version = 1.3.0
version = 1.3.1
8 changes: 7 additions & 1 deletion src/main/resources/site/processors/matomo-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ exports.responseProcessor = function (req, res) {
hash = hashCode(req.cookies["no-bouvet-app-matomo_disabled"] + ""); // Create a unique hash if user has consented to tracking.
}

res.pageContributions.headEnd.push("<script async defer src=\"matomo.js?" + hash + "\"></script>");
let siteRootPath = portalLib.pageUrl({ id: portalLib.getSite()._id });
// Site vhost is mounted on domain root, e.g. www.example.com
if (siteRootPath === "/") {
siteRootPath = "";
}

res.pageContributions.headEnd.push("<script async defer src=\"" + siteRootPath + "/matomo.js?" + hash + "\"></script>");
if (matomoTagManagerContainerId) {
res.pageContributions.headEnd.push("<script async defer src=\"" + matomoJavaScriptUrl + "/container_" + matomoTagManagerContainerId + ".js\"></script>");
}
Expand Down

0 comments on commit 2b50a55

Please sign in to comment.