diff --git a/website/public/api/v1/gaufre.js b/website/public/api/v1/gaufre.js index 5fbfeb4..cfc36d0 100644 --- a/website/public/api/v1/gaufre.js +++ b/website/public/api/v1/gaufre.js @@ -81,7 +81,7 @@ html = html.replace(/(src=|href=|url\()"\//g, `$1"${origin}/`) const parser = new DOMParser() const popupDocument = parser.parseFromString(html, "text/html") - popup.innerHTML = popupDocument.body.innerHTML + popup.innerHTML = addStatisticsParams(popupDocument.body) document.body.appendChild(popup) return popup }) @@ -224,4 +224,25 @@ } window.document.documentElement.classList.remove("lasuite--gaufre-modal-opened") } + + const addStatisticsParams = (popupBody) => { + const serviceAnchors = popupBody.querySelectorAll(".lagaufre-service__name") + const currentHostname = new URL(window.location.href).hostname + const currentHostnameInGaufre = Array.from(serviceAnchors).find( + (anchor) => new URL(anchor.href).hostname === currentHostname, + ) + const currentServiceId = currentHostnameInGaufre + ? currentHostnameInGaufre.getAttribute("data-gaufre-service-id") + : null + if (!currentServiceId) { + return popupBody.innerHTML + } + serviceAnchors.forEach((anchor) => { + const url = new URL(anchor.href) + url.searchParams.set("mtm_campaign", `${currentServiceId}-gaufre`) + url.searchParams.set("utm_source", `${currentServiceId}-gaufre`) + anchor.href = url.toString() + }) + return popupBody.innerHTML + } })() diff --git a/website/src/components/GaufrePage.astro b/website/src/components/GaufrePage.astro index 5436e5c..d88bebc 100644 --- a/website/src/components/GaufrePage.astro +++ b/website/src/components/GaufrePage.astro @@ -340,6 +340,7 @@ const useSubsettedFont = import.meta.env.PUBLIC_USE_GAUFRE_SUBSETTED_FONT !== "0 aria-label={ariaLabel} class="lagaufre-service__name" href={url} + data-gaufre-service-id={id} id={`lagaufre-service-${id}`} {...((i === 0 && { autofocus: true }) || {})} >