Skip to content

Commit

Permalink
add matomo tagmanager url
Browse files Browse the repository at this point in the history
  • Loading branch information
IvoLeist committed Nov 29, 2023
1 parent aebad6a commit ff0262e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
9 changes: 1 addition & 8 deletions convertPheno_client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
<meta name="maintainer" content="Ivo Christopher Leist" />
<meta name="license" content="GPLv3" />
<title>Convert-Pheno</title>
<script>
var _mtm = window._mtm = window._mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
(function() {
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src='{{MATOMO_TAG_MANAGER_URL}}'; s.parentNode.insertBefore(g,s);
})();
</script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand All @@ -28,6 +20,7 @@
window.REACT_APP_SECURITY = "{{VITE_SECURITY}}";
window.REACT_APP_API_URL = "{{VITE_API_URL}}";
window.REACT_APP_KC_CONFIG = "{{VITE_KC_CONFIG}}";
window.REACT_APP_MATOMO_URL = "{{MATOMO_TAG_MANAGER_URL}}";
</script>
<script type="module" src="/src/main.tsx"></script>
</body>
Expand Down
14 changes: 14 additions & 0 deletions convertPheno_client/src/code/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ const security =
? window.REACT_APP_SECURITY
: import.meta.env.VITE_SECURITY;

const matomoUrl =
process.env.NODE_ENV === "production"
? JSON.parse(window.REACT_APP_MATOMO_URL.replace(/'/g, '"'))
: JSON.parse(import.meta.env.MATOMO_TAG_MANAGER_URL);

console.log("Matomo URL: ", matomoUrl);

if (security !== "true" && security !== "false") {
throw new Error(
"The security variable must be a string of either 'true' or 'false'"
Expand Down Expand Up @@ -128,6 +135,13 @@ function App() {

const [authenticated, setAuthenticated] = useState(false);

useEffect(() => {
var _mtm = window._mtm = window._mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=matomoUrl; s.parentNode.insertBefore(g,s);
}, [])

useEffect(() => {
if (auth.user.authenticated) {
setAuthenticated(true);
Expand Down

0 comments on commit ff0262e

Please sign in to comment.