Utilizing Cvars to Capture Custom URL Parameter Values Within Custom Fields

CTM’s cvar functionality can be used to capture values from URLs or cookies on your site. The following instructions can be used to collect, store, and map data from your website as custom CVar values. 

This can be done in plans that have access to triggers: Marketing Pro, Sales Engage, Enterprise, Connect, and Growth.

This is also useful when capturing fbclid as demonstrated below:
  

  1. Add custom tracking code as shown below to the section “Custom Tracking Code” under Numbers> Tracking Code> Custom Tracking Code:

 try {

    var __ctm_cvars = __ctm_cvars || [];

 
 

    // Function to get a cookie value

    function getCookieValue(name) {

        const match = document.cookie.split("; ").find(coo => coo.startsWith(name + "="));

        return match ? match.split("=")[1] : null;

    }

     // Function to get a query parameter from the URL

    function getQueryParam(name) {

        const urlParams = new URLSearchParams(window.location.search);

        return urlParams.get(name);

    }

     // Capture values

    var _fbclid = getQueryParam("fbclid");  // from URL

    var _customid = getQueryParam("customid");  // from URL

    var _fbp = getCookieValue("_fbp");      // from cookies

 
    // Push into cvars

    __ctm_cvars.push({

        _fbclid: _fbclid,

        _customid: _customid,

        _fbp: _fbp

    });

} catch (e) {

    console.error('Error capturing Facebook session IDs:', e);

}

 


 

This will cause the tracking code to store the captured URL parameter as a cvar value within the session data for an activity, as shown below for fbclid in the screenshot below by the cvar “_fbclid” being set as value “987123” from the landing URL:

 You can check that your cvar is being pulled correctly on your website by utilizing the command __ctm_cvars within the console of your browser: 

 2. Add a trigger to map the custom cvar value to a custom field (in this case, we've utilized a custom field called fbclid to store the _fbclid cvar value):

 3. If you’d like to also pass this custom field value to a CRM integration, such as Salesforce, then you can add an action within the trigger to pass the custom field’s value through after the custom value is set, as shown below:

 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.