2026-01-21 13:37:26 +01:00
|
|
|
export class UtmAccount extends HTMLElement {
|
2026-01-27 20:24:02 +01:00
|
|
|
async connectedCallback() {
|
|
|
|
|
// 1. Vérification du consentement
|
|
|
|
|
if (sessionStorage.getItem('ldk_cookie') !== 'accepted') return;
|
|
|
|
|
|
|
|
|
|
// 2. Vérification de la présence d'Umami (nécessaire si tu utilises l'objet global umami ailleurs)
|
2026-01-21 13:37:26 +01:00
|
|
|
if (typeof umami === 'undefined') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 20:24:02 +01:00
|
|
|
const userId = this.getAttribute('id');
|
|
|
|
|
const userName = this.getAttribute('name');
|
|
|
|
|
const userEmail = this.getAttribute('email');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 3. Envoi de l'identification à ton instance Umami (Tools Security)
|
|
|
|
|
const response = await fetch("https://tools-security.esy-web.dev/api/send", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
"type": "identify",
|
|
|
|
|
"payload": {
|
|
|
|
|
"website": "bc640e0d-43fb-4c3a-bb17-1ac01cec9643",
|
|
|
|
|
"screen": `${window.screen.width}x${window.screen.height}`,
|
|
|
|
|
"language": navigator.language,
|
|
|
|
|
"title": document.title,
|
|
|
|
|
"hostname": window.location.hostname,
|
|
|
|
|
"url": window.location.pathname,
|
|
|
|
|
"referrer": document.referrer,
|
|
|
|
|
"id": `user_${userId}`,
|
|
|
|
|
"data": { "name": userName, "email": userEmail }
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
const sessionId = result.sessionId;
|
|
|
|
|
|
|
|
|
|
// 4. Envoi du sessionId à ton backend Symfony
|
|
|
|
|
if (sessionId) {
|
2026-02-09 14:06:26 +01:00
|
|
|
await fetch('/umami', {
|
2026-01-27 20:24:02 +01:00
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({ umami_session: sessionId })
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
}
|
2026-01-21 13:37:26 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-01-27 20:24:02 +01:00
|
|
|
|
2026-01-21 13:37:26 +01:00
|
|
|
export class UtmEvent extends HTMLElement {
|
|
|
|
|
connectedCallback() {
|
2026-01-27 20:24:02 +01:00
|
|
|
// On ne tracke que si les cookies sont acceptés
|
|
|
|
|
if (sessionStorage.getItem('ldk_cookie') !== 'accepted') return;
|
|
|
|
|
|
2026-01-21 13:37:26 +01:00
|
|
|
if (typeof umami === 'undefined') {
|
|
|
|
|
console.warn('Umami script non détecté.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const event = this.getAttribute('event');
|
|
|
|
|
const dataRaw = this.getAttribute('data');
|
|
|
|
|
|
2026-01-27 20:24:02 +01:00
|
|
|
// Extraction dynamique du website-id
|
2026-01-21 13:37:26 +01:00
|
|
|
const umamiScript = document.querySelector('script[data-website-id]');
|
|
|
|
|
const websiteId = umamiScript ? umamiScript.getAttribute('data-website-id') : null;
|
|
|
|
|
|
|
|
|
|
if (!websiteId) {
|
|
|
|
|
console.error('Impossible de trouver le data-website-id umami.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-01-27 20:24:02 +01:00
|
|
|
if (event === "click_pdf_product") {
|
2026-01-22 15:58:57 +01:00
|
|
|
const data = JSON.parse(dataRaw);
|
|
|
|
|
umami.track({
|
|
|
|
|
website: websiteId,
|
2026-01-27 20:24:02 +01:00
|
|
|
name: 'Téléchargement document produit',
|
2026-01-22 15:58:57 +01:00
|
|
|
data: data
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-01-21 13:37:26 +01:00
|
|
|
if (event === "view_catalogue") {
|
|
|
|
|
umami.track('Affichage du catalogue');
|
|
|
|
|
}
|
2026-01-21 13:39:46 +01:00
|
|
|
if (event === "view_home") {
|
|
|
|
|
umami.track('Affichage de la page accueil');
|
|
|
|
|
}
|
2026-01-21 13:37:26 +01:00
|
|
|
if (event === "view_contact") {
|
|
|
|
|
umami.track('Affichage du page contact');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event === "view_product" && dataRaw) {
|
|
|
|
|
const data = JSON.parse(dataRaw);
|
|
|
|
|
umami.track({
|
|
|
|
|
website: websiteId,
|
2026-01-27 20:24:02 +01:00
|
|
|
name: 'Affichage produit',
|
2026-01-21 13:37:26 +01:00
|
|
|
data: data
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Erreur lors du tracking Umami:', e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|