Understanding and implementing effective website tracking and user engagement tools is crucial for optimizing your digital strategy. Let’s explore how to integrate tools like Google Tag Manager, Facebook Pixel, and Survicate to gain valuable insights into your audience and improve their experience.
First, it’s important to determine your user’s subscription status and geolocation. This information allows for personalized experiences and targeted campaigns. Typically, this involves checking for a window?.geoinfo?.CountryCode and defaulting to ‘IN’ if unavailable.
Next, you can leverage visitor traits through platforms like Survicate. Specifically, w._sva.setVisitorTraits allows you to send data regarding user subscription status (toi_user_subscription_status) and geolocation (toi_user_geolocation).
However, Survicate’s integration requires a bit of finesse. If w._sva and w._sva.setVisitorTraits are instantly available,you can proceed with setting attributes directly. Otherwise, you should listen for a “SurvicateReady” event to ensure the platform is fully loaded before attempting to set these traits.
To load the Survicate script,a dynamic script tag is added to your page.This script, sourced from https://survey.survicate.com/workspaces/0be6ae9845d14a7c8ff08a7a00bd9b21/web_surveys.js, is inserted before the existing script tags to ensure proper loading. It’s set to load asynchronously for optimal page performance.
Now, let’s discuss triggering these integrations based on your site’s configuration. I’ve found that checking for specific settings within a configuration object (f.toiplus_site_settings) is a reliable approach.This includes verifying the active status of Facebook and Google campaigns (isFBCampaignActive, isGoogleCampaignActive).
If the configuration is available and the user isn’t a prime subscriber, you can immediately load the necessary event tracking scripts. This includes loading Google Tag Manager events via loadGtagEvents and Facebook Pixel events via loadFBEvents, followed by the Survicate script using loadSurvicateJs.
However, if the initial configuration isn’t available, or if the user is a prime subscriber, a fallback mechanism is essential. This involves fetching site settings from an external source,such as a Jarvis endpoint (https://jarvis.indiatimes.com/v1/feeds/toi_plus/site_settings/643526e21443833f0c454615?db_env=published).
Here’s what works best: upon receiving the configuration data, you can then conditionally load the appropriate Survicate sections. For prime users, you might use config?.allowedSurvicatePrimeSections, while non-prime users would utilize config?.allowedSurvicateSections. Subsequently, Google and Facebook events are loaded based on the configuration’s active campaign flags.
To summarize, here’s a breakdown of the key steps:
* Determine User Status: Check for prime subscription and geolocation.
* Set Visitor Traits: Utilize w._sva.setVisitorTraits to send subscription and location data to Survicate.
* Dynamic Script Loading: Load the Survicate script asynchronously.
* Configuration check: Verify the availability of site settings.
* Conditional Loading: Load events and Survicate sections based on configuration and user status.
* Fallback Mechanism: Fetch site settings from an external source if the initial configuration is unavailable.