Skip to content

Commit

Permalink
update script for matomo tag manager
Browse files Browse the repository at this point in the history
  • Loading branch information
MarBert committed Jan 9, 2025
1 parent f5ad1f3 commit 9b01ae6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
27 changes: 11 additions & 16 deletions apps/nextjs-website/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
cookieDomainScript,
isChatbotActive,
isProduction,
matomoScriptSrc,
} from '@/config';
import { Metadata } from 'next';
import 'swiper/css';
Expand All @@ -23,22 +24,16 @@ import { Titillium_Web } from 'next/font/google';
import NextIntlContext from '@/components/atoms/NextIntlContext/NextIntlContext';
import ChatbotProvider from '@/components/organisms/ChatbotProvider/ChatbotProvider';

const MATOMO_SCRIPT = `
var _paq = (window._paq = window._paq || []);
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function () {
var u = "https://pagopa.matomo.cloud/";
_paq.push(["setTrackerUrl", u + "matomo.php"]);
_paq.push(["setSiteId", "8"]);
var d = document,
g = d.createElement("script"),
s = d.getElementsByTagName("script")[0];
g.async = true;
g.src = "//cdn.matomo.cloud/pagopa.matomo.cloud/matomo.js";
s.parentNode.insertBefore(g, s);
})();
const MATOMO_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='` +
matomoScriptSrc +
`'; s.parentNode.insertBefore(g,s);
})();
`;

const titilliumWeb = Titillium_Web({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ const ChatButton = ({ isChatOpen, onOpenChat, size }: ChatButtonProps) => {
return (
<Box sx={{ opacity: isChatOpen ? 0 : 1 }}>
<Fab
id='chatbot'
aria-label='chat'
onClick={(e) => {
matomoEvent();
//matomoEvent();
onOpenChat(e);
}}
size={size}
Expand Down
1 change: 1 addition & 0 deletions apps/nextjs-website/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ See BrowserConfig.ts and BrowserEnv.ts as examples.
// TODO: Add environment parser
export const docsPath = process.env.PATH_TO_GITBOOK_DOCS;
export const cookieDomainScript = process.env.NEXT_PUBLIC_COOKIE_DOMAIN_SCRIPT;
export const matomoScriptSrc = process.env.NEXT_PUBLIC_MATOMO_SCRIPT_SRC;
export const environment = process.env.ENVIRONMENT;
export const docsAssetsPath = '/gitbook/docs';
export const allowCrawler = process.env.ALLOW_CRAWLER === 'true';
Expand Down

0 comments on commit 9b01ae6

Please sign in to comment.