Problem Statement #
UTM parameters are not getting captured for the tracking URL.
The CX is using their own website with a custom form instead of a LeadSquared landing page form.
Root Cause Analysis (RCA) #
-
The tracking script is installed correctly.
-
Prospects are being generated successfully.
-
The issue occurs during lead capture because the Prospect ID is not being passed in the payload.
When using a custom form (V2 API), the JavaScript global variable MXCProspectId must be picked from the browser and passed along with the API payload.
Additionally:
-
For existing leads, the API response returns the original Prospect ID.
-
This returned Prospect ID must be updated in the browser to ensure proper tracking continuity.
If this step is missed, UTM attribution will not work correctly.
Solution #
The following JavaScript function must be added to the CX’s website to properly set and update the Prospect ID:
function setProspectParameters(leadId, orgCode, trackingDomain) {
let expiryDate = new Date();
expiryDate.setTime(expiryDate.getTime() + (365 * 24 * 60 * 60 * 1000));
document.cookie = 'ORG' + orgCode + '=' + leadId + ';expires=' + expiryDate.toUTCString() + ';Domain=' + trackingDomain + ';path=/;';
MXCProspectId = leadId;
window.leadsquared.tracker.pids[orgCode] = leadId;
}
// Sample function call
// Replace 77318 with the org code and clientdomain.com with the website domain where it is used
setProspectParameters(leadId, 77318, 'clientdomain.com');
Important #
-
This implementation is required only when the CX is using a custom form with the V2 API.
-
If the CX is using a LeadSquared landing page form, this step is not required, as Prospect ID handling is managed automatically.
Expected Outcome #
Once the Prospect ID is correctly passed and updated in the browser:
-
UTM parameters will be captured accurately.
-
Lead attribution will function as expected.
-
Tracking continuity will be maintained for both new and existing leads.
