Objectif : Ce script JavaScript est conçu pour intégrer divers outils de suivi et d’analyze dans un site web, plus précisément une propriété du groupe Times (probablement times Internet). Il se concentre sur :
- Segmentation des utilisateurs : Identifier si un utilisateur est un abonné payant (“utilisateur prime”) et sa localisation géographique.
- Suivi des événements : Charger et déclencher des événements pour Google Tag Manager (Gtag), Facebook Pixel et Survicate.
- configuration dynamique : Récupérer des données de configuration (éventuellement à partir d’un point de terminaison côté serveur) pour déterminer quels outils de suivi charger et comment les configurer.
- Chargement conditionnel : Charger les scripts de suivi uniquement sous certaines conditions (par exemple,si l’utilisateur n’est pas un utilisateur prime,ou en fonction des paramètres de configuration).
TimesApps.toiPlusEvents(config)Fonction :
- C’est le point d’entrée principal du script. Il est appelé avec un objet
config(bien qu’il puisse également être appelé sans config, auquel cas il tente d’en récupérer un). - Il vérifie si les données de configuration sont disponibles directement dans une variable globale
f(plus précisémentf.toiplussitesettings). - Il vérifie si l’utilisateur est un utilisateur prime (
window.isPrimeetwindow.isPrimeUserLayout). - En fonction de ces vérifications,
- Variables Globales et Configuration :
toiplussitesettings: Un objet contenant des paramètres de configuration pour le site web, y compris des indicateurs pour activer ou désactiver certains outils de suivi.JarvisUrl: L’URL d’un point de terminaison pour récupérer des données de configuration supplémentaires.allowedSurvicateSections: Un paramètre qui spécifie probablement les sections du site web qui doivent être suivies par Survicate (par exemple, des pages ou des fonctionnalités spécifiques).
- Intégration des Outils de Suivi :
- google Tag manager (Gtag) : Le script charge Gtag et envoie un événement
page_view. - Facebook Pixel : Le script charge le Facebook Pixel et envoie un événement
PageView. - Survicate : Le script charge Survicate et définit des attributs utilisateur, tels que le code pays (par défaut “IN” si non disponible).
setAttributes()Fonction :
- Cette fonction (non entièrement affichée) est appelée après l’initialisation de Survicate. Elle définit probablement des traits de visiteur ou des configurations supplémentaires dans Survicate.
window.getFromClient(JarvisUrl, callback):
- Cette fonction (non entièrement affichée) est une fonction personnalisée qui effectue une requête asynchrone vers le point de terminaison
JarvisUrlpour récupérer des données de configuration. - Elle appelle la fonction
callbackavec les données de configuration récupérées.
Observations Clés
- Piloté par la configuration : Le script est hautement configurable. Le comportement des outils de suivi est déterminé par l’objet
toiplussitesettings(soit directement dans le code, soit récupéré à partir d’un point de terminaison).
Okay, I’ve analyzed the provided JavaScript code snippet. Hear’s a breakdown of what it does, focusing on its purpose and key functionalities. I’ll also address the “OBJECTIF” comment at the end, as it truly seems to indicate a task related to article content.
Overall Purpose
This JavaScript code is designed to integrate various tracking and analytics tools into a website, specifically a Times Group (likely Times Internet) property. It focuses on:
User Segmentation: Identifying whether a user is a paid subscriber (“prime user”) and their geographic location.
Event Tracking: Loading and triggering events for Google Tag Manager (Gtag),Facebook Pixel,and Survicate.
Dynamic Configuration: Fetching configuration data (possibly from a server-side endpoint) to determine which tracking tools to load and how to configure them.
Conditional Loading: Loading tracking scripts only under certain conditions (e.g., if the user is not a prime user, or based on configuration settings).
Detailed Breakdown
-
TimesApps.toiPlusEvents(config)Function:
This is the main entry point of the script. It’s called with a config object (though it can also be called without a config, in which case it attempts to fetch one).
It checks if configuration data is available directly in a global variable f (specifically f.toiplussitesettings).
It checks if the user is a prime user (window.isPrime and window.isPrimeUserLayout).
Based on these checks, it decides whether to:
Directly load tracking events: If configuration is available in f and the user is not a prime user, it calls loadGtagEvents, loadFBEvents, and loadSurvicateJs instantly.
Fetch configuration from an endpoint: If configuration is not available in f, it calls window.getFromClient to fetch it from a URL (JarvisUrl – the URL is incomplete in the provided code). Once the configuration is fetched, it calls the same tracking functions (loadGtagEvents, loadFBEvents, loadSurvicateJs) with the fetched configuration data. It uses different Survicate sections based on whether the user is a prime user layout.
-
loadGtagEvents(isGoogleCampaignActive):
This function (not fully shown) is responsible for loading and initializing Google Tag Manager (Gtag) events.
The isGoogleCampaignActive parameter likely determines whether to load specific Gtag events related to Google advertising campaigns.
-
loadFBEvents(isFBCampaignActive):
This function (not fully shown) is responsible for loading and initializing Facebook Pixel events.
The isFBCampaignActive parameter likely determines whether to load specific Facebook Pixel events related to Facebook advertising campaigns.
-
loadSurvicateJs(allowedSurvicateSections):
This function is the most complex part of the code.It’s responsible for loading the Survicate JavaScript library and configuring it.
It sets visitor traits (user properties) in Survicate:
toiusersubscriptionstatus: Determines if the user is a paid subscriber (“paid” or “free”).
toiusergeolocation: Sets the user’s country code (defaults to “IN” if not available).
It ensures that the setAttributes function is called after Survicate is initialized. It uses an event listener (addEventListener("SurvicateReady", setAttributes)) to wait for Survicate to be ready if it’s not already loaded.
It dynamically creates a tag to load the Survicate JavaScript file.
The allowedSurvicateSections parameter likely specifies which sections of the website should be tracked by Survicate (e.g.,specific pages or features).
-
setAttributes()Function:
This function (not fully shown) is called after Survicate is initialized. it likely sets additional visitor traits or configurations in Survicate.
-
window.getFromClient(JarvisUrl, callback):
This function (not fully shown) is a custom function that makes an asynchronous request to the JarvisUrl endpoint to fetch configuration data.
It calls the callback function with the fetched configuration data.
Key Observations
* Configuration-Driven: The script is highly configurable. The behavior of the tracking tools is steadfast by the toiplussite_settings object (either directly in the code or fetched from an endpoint).
