gaufre: add url param tags to have a better idea how the gaufre is used

This commit is contained in:
Emmanuel Pelletier
2025-04-17 16:23:51 +02:00
parent 800ab42eaf
commit 970f41d14c
2 changed files with 23 additions and 1 deletions

View File

@@ -81,7 +81,7 @@
html = html.replace(/(src=|href=|url\()"\//g, `$1"${origin}/`) html = html.replace(/(src=|href=|url\()"\//g, `$1"${origin}/`)
const parser = new DOMParser() const parser = new DOMParser()
const popupDocument = parser.parseFromString(html, "text/html") const popupDocument = parser.parseFromString(html, "text/html")
popup.innerHTML = popupDocument.body.innerHTML popup.innerHTML = addStatisticsParams(popupDocument.body)
document.body.appendChild(popup) document.body.appendChild(popup)
return popup return popup
}) })
@@ -224,4 +224,25 @@
} }
window.document.documentElement.classList.remove("lasuite--gaufre-modal-opened") 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
}
})() })()

View File

@@ -340,6 +340,7 @@ const useSubsettedFont = import.meta.env.PUBLIC_USE_GAUFRE_SUBSETTED_FONT !== "0
aria-label={ariaLabel} aria-label={ariaLabel}
class="lagaufre-service__name" class="lagaufre-service__name"
href={url} href={url}
data-gaufre-service-id={id}
id={`lagaufre-service-${id}`} id={`lagaufre-service-${id}`}
{...((i === 0 && { autofocus: true }) || {})} {...((i === 0 && { autofocus: true }) || {})}
> >