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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV-2075] use matomo tag manager #1295

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
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
6 changes: 6 additions & 0 deletions .changeset/flat-steaks-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"infrastructure": patch
"nextjs-website": patch
---

Add local variable and new script for Matomo tag manager
1 change: 1 addition & 0 deletions .github/actions/build-nextjs-website/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ runs:
NEXT_PUBLIC_ORGANIZATION_LOGO: ${{ inputs.organization_logo }}
NEXT_PUBLIC_ORGANIZATION_SOCIAL_LINKS: ${{ inputs.organization_social_links }}
NEXT_PUBLIC_CHATBOT_ACTIVE: ${{ inputs.chatbot_active }}
NEXT_PUBLIC_MATOMO_SCRIPT_SRC: ${{ inputs.matomo_script_src }}
STRAPI_ENDPOINT: ${{ inputs.strapi_endpoint }}
STRAPI_API_TOKEN: ${{ inputs.strapi_api_token }}
FETCH_FROM_STRAPI: ${{ inputs.fetch_from_strapi }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy_website.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
strapi_endpoint: ${{ vars.STRAPI_ENDPOINT }}
strapi_api_token: ${{ secrets.STRAPI_API_TOKEN }}
fetch_from_strapi: ${{ vars.FETCH_FROM_STRAPI }}
matomo_script_src: ${{ vars.NEXT_PUBLIC_MATOMO_SCRIPT_SRC }}

manual_deploy:
name: Deploy to S3 (manual on ${{ inputs.environment }})
Expand Down Expand Up @@ -116,3 +117,4 @@ jobs:
strapi_endpoint: ${{ vars.STRAPI_ENDPOINT }}
strapi_api_token: ${{ secrets.STRAPI_API_TOKEN }}
fetch_from_strapi: ${{ vars.FETCH_FROM_STRAPI }}
matomo_script_src: ${{ vars.NEXT_PUBLIC_MATOMO_SCRIPT_SRC }}
1 change: 1 addition & 0 deletions .github/workflows/deploy_website_content.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ jobs:
strapi_endpoint: ${{ vars.STRAPI_ENDPOINT }}
strapi_api_token: ${{ secrets.STRAPI_API_TOKEN }}
fetch_from_strapi: ${{ vars.FETCH_FROM_STRAPI }}
matomo_script_src: ${{ vars.NEXT_PUBLIC_MATOMO_SCRIPT_SRC }}
33 changes: 24 additions & 9 deletions apps/nextjs-website/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
baseUrl,
cookieDomainScript,
isChatbotActive,
isProduction,
matomoScriptSrc,
} from '@/config';
import { Metadata } from 'next';
import 'swiper/css';
Expand Down Expand Up @@ -40,6 +40,17 @@ _paq.push(["enableLinkTracking"]);
s.parentNode.insertBefore(g, s);
})();
`;
const MATOMO_TAG_MANAGER_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({
fallback: ['serif'],
Expand Down Expand Up @@ -79,14 +90,18 @@ export default async function RootLayout({
return (
<html lang='it' className={titilliumWeb.variable}>
<head>
{isProduction && (
<Script
id='matomo'
key='script-matomo'
dangerouslySetInnerHTML={{ __html: MATOMO_SCRIPT }}
strategy='lazyOnload'
/>
)}
<Script
id='matomo'
key='script-matomo'
dangerouslySetInnerHTML={{ __html: MATOMO_SCRIPT }}
strategy='lazyOnload'
/>
<Script
id='matomo-tag-manager'
key='script-matomo-tag-manager'
dangerouslySetInnerHTML={{ __html: MATOMO_TAG_MANAGER_SCRIPT }}
strategy='lazyOnload'
/>
</head>
<ThemeRegistry options={{ key: 'mui' }}>
<NextIntlContext
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();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this line is no longer necessary it could be removed

Suggested change
//matomoEvent();

onOpenChat(e);
}}
size={size}
Expand All @@ -35,6 +36,7 @@ const ChatButton = ({ isChatOpen, onOpenChat, size }: ChatButtonProps) => {
}}
>
<IconWrapper
id={'chatbotIcon'}
icon={'/icons/chatbotAvatar.svg'}
useSrc={true}
color={palette.text.secondary}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Image from 'next/image';
import { ICON_MAP } from './IconMap';

export type IconWrapperProps = {
id?: string;
icon: string;
useSrc: boolean;
color?: string;
Expand All @@ -15,6 +16,7 @@ export type IconWrapperProps = {
type IconName = keyof typeof ICON_MAP;

const IconWrapper = ({
id,
icon,
useSrc,
color = 'text.primary',
Expand All @@ -23,7 +25,14 @@ const IconWrapper = ({
}: IconWrapperProps) => {
if (useSrc) {
return (
<Icon sx={{ width: size, height: size, color, ...sx }}>
<Icon id={id} sx={{ width: size, height: size, color, ...sx }}>
<Image
id={id ? `${id}Image` : undefined}
alt={icon}
src={icon}
height={size}
width={size}
/>
<Image alt={icon} src={icon} height={size} width={size} />
</Icon>
);
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
Loading