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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matomo Support #111

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export const runtimeConfig =
TWITTER_SITE: window?.env?.TWITTER_SITE,
TWITTER_CREATOR: window?.env?.TWITTER_CREATOR,
GHOST: window?.env?.GHOST,
MATOMO_URL: window?.env?.MATOMO_URL,
MATOMO_SITE_ID: window?.env?.MATOMO_SITE_ID,
}
: {
// server
Expand Down Expand Up @@ -323,4 +325,10 @@ export const runtimeConfig =
? process.env.TWITTER_CREATOR
: process.env.RAZZLE_TWITTER_CREATOR,
GHOST: nodeIsProduction ? process.env.GHOST : process.env.RAZZLE_GHOST,
MATOMO_URL: nodeIsProduction
? process.env.MATOMO_URL
: process.env.RAZZLE_MATOMO_URL,
MATOMO_SITE_ID: nodeIsProduction
? process.env.MATOMO_SITE_ID
: process.env.RAZZLE_MATOMO_SITE_ID,
};
24 changes: 24 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,30 @@ server
</script>`
: ''
}
${
runtimeConfig.MATOMO_URL && runtimeConfig.MATOMO_SITE_ID
? `
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
Copy link

@samip5 samip5 Mar 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be configureable, as if I remember correctly, there's multiple one can add or not have and one shouldn't rely only on the JS code, unless client has to have js enabled too for the whole app to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't exactly know what this image tracking was and it didn't allow it in the head tag.
I just read how it works and it's basically what you are mentioning here.
I'm going to make a new pull request, already tested and it works on edge with javascript disabled (not allowed)

_paq.push(['enableLinkTracking']);
(function () {
var u = "${runtimeConfig.MATOMO_URL}";
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setSiteId', '${runtimeConfig.MATOMO_SITE_ID}']);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
})();
</script>
<!-- Matomo End -->`
: ''
}

</head>
<body>
Expand Down