miniature-iron-53243
12/20/2023, 11:00 AMmillions-activity-52391
12/20/2023, 11:00 AMminiature-iron-53243
12/20/2023, 11:00 AMfunction captureLeadOnceFromLocalStorage() {
const domain = window.location.hostname;
const hasLeadCaptured = localStorage.getItem(`leadCaptured:${domain}`);
if (!hasLeadCaptured) {
identify();
rudderanalytics.track('Lead');
localStorage.setItem(`leadCaptured:${domain}`, 'true');
console.log('Lead call triggered using local storage values');
} else {
console.log('Lead already captured for this user');
}
}
// Call the function to capture lead once on page load
window.addEventListener('load', function () {
captureLeadOnceFromLocalStorage();
});
function identify() {
const domain = window.location.hostname;
const localStorageKeys = Object.keys(localStorage);
const inputValues = {};
const userId = localStorage.getItem("cf_uvid");
const fbpLocalStorage = localStorage.getItem('fbp');
const fbclid = formatFBCLID(localStorage.getItem('fbclid'));
localStorageKeys.forEach((key) => {
if (key.startsWith(`garlic:${domain}*>input.`)) {
const inputField = key.split('input.')[1];
const value = localStorage.getItem(key) || '';
inputValues[inputField] = value;
}
});
// Passing local storage values fbp, fbc, and formatted fbclid in the identify call separately
rudderanalytics.identify(userId, {
first_name: inputValues['first_name'] || '',
last_name: inputValues['last_name'] || '',
phone: inputValues['phone'] || '',
email: inputValues['email'] || ''
}, {
fbp: fbpLocalStorage || '', // Using fbp value from local storage
fbc: fbclid || '' // Using fbclid value from local storage
});
}
// Function to format fbclid
function formatFBCLID(fbclid) {
if (fbclid) {
const timeStamp = Math.floor(Date.now() / 1000); // Get current timestamp in seconds
return `fb.1.${timeStamp}.${fbclid}`;
}
return '';
}miniature-iron-53243
12/20/2023, 11:01 AMmillions-activity-52391
12/21/2023, 3:10 PMminiature-iron-53243
12/21/2023, 3:15 PM{
"anonymousId": "4415e5be-1b3e-42d9-b2b8-ca62212987e0",
"channel": "web",
"context": {
"app": {
"name": "RudderLabs JavaScript SDK",
"namespace": "com.rudderlabs.javascript",
"version": "2.46.0"
},
"campaign": {},
"fbc": "fb.1.1703171705.abc1233",
"fbp": "fb.1.1702993095356.423252697",
"library": {
"name": "RudderLabs JavaScript SDK",
"version": "2.46.0"
},
"locale": "en-US",
"os": {
"name": "",
"version": ""
},
"page": {
"initial_referrer": "$direct",
"initial_referring_domain": "",
"path": "/order-form-591807531683320674934",
"referrer": "https://www.redlighthealthstar.com/optin-591807521683320668282?fbclid=abc1233",
"referring_domain": "www.redlighthealthstar.com",
"search": "?cf_uvid=dd3b917c7ede868ba450b0d13fd60466",
"tab_url": "https://www.redlighthealthstar.com/order-form-591807531683320674934?cf_uvid=dd3b917c7ede868ba450b0d13fd60466",
"title": "Discovery Package Checkout | Red Light Therapy Body Contouring | Health Star",
"url": "https://www.redlighthealthstar.com/order-form-591807531683320674934?cf_uvid=dd3b917c7ede868ba450b0d13fd60466"
},
"screen": {
"density": 1,
"height": 768,
"innerHeight": 679,
"innerWidth": 1366,
"width": 1366
},
"sessionId": 1703171705189,
"sessionStart": true,
"timezone": "GMT+0530",
"traits": {
"email": "test3@data.com",
"first_name": "FB",
"last_name": "test",
"phone": "9876"
},
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
},
"integrations": {
"All": true
},
"messageId": "53381c0f-4345-42d9-aa3f-6b93fd62b4c5",
"originalTimestamp": "2023-12-21T15:15:05.192Z",
"rudderId": "94a18824-e692-4343-a88b-bcb30f39e6c5",
"sentAt": "2023-12-21T15:15:05.197Z",
"type": "identify",
"userId": "dd3b917c7ede868ba450b0d13fd60466"
}miniature-iron-53243
12/21/2023, 3:15 PM{
"anonymousId": "4415e5be-1b3e-42d9-b2b8-ca62212987e0",
"channel": "web",
"context": {
"app": {
"name": "RudderLabs JavaScript SDK",
"namespace": "com.rudderlabs.javascript",
"version": "2.46.0"
},
"campaign": {},
"library": {
"name": "RudderLabs JavaScript SDK",
"version": "2.46.0"
},
"locale": "en-US",
"os": {
"name": "",
"version": ""
},
"page": {
"initial_referrer": "$direct",
"initial_referring_domain": "",
"path": "/order-form-591807531683320674934",
"referrer": "https://www.redlighthealthstar.com/optin-591807521683320668282?fbclid=abc1233",
"referring_domain": "www.redlighthealthstar.com",
"search": "?cf_uvid=dd3b917c7ede868ba450b0d13fd60466",
"tab_url": "https://www.redlighthealthstar.com/order-form-591807531683320674934?cf_uvid=dd3b917c7ede868ba450b0d13fd60466",
"title": "Discovery Package Checkout | Red Light Therapy Body Contouring | Health Star",
"url": "https://www.redlighthealthstar.com/order-form-591807531683320674934?cf_uvid=dd3b917c7ede868ba450b0d13fd60466"
},
"screen": {
"density": 1,
"height": 768,
"innerHeight": 679,
"innerWidth": 1366,
"width": 1366
},
"sessionId": 1703171705189,
"timezone": "GMT+0530",
"traits": {
"email": "test3@data.com",
"first_name": "FB",
"last_name": "test",
"phone": "9876"
},
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
},
"event": "Lead",
"integrations": {
"All": true
},
"messageId": "5a6f81a6-63f2-4731-8543-69c3907f4334",
"originalTimestamp": "2023-12-21T15:15:05.198Z",
"properties": {},
"rudderId": "94a18824-e692-4343-a88b-bcb30f39e6c5",
"sentAt": "2023-12-21T15:15:05.201Z",
"type": "track",
"userId": "dd3b917c7ede868ba450b0d13fd60466"
}miniature-iron-53243
12/21/2023, 3:16 PM{
"body": {
"XML": {},
"FORM": {
"data": [
"{\"user_data\":{\"external_id\":\"bb013148ceb6975e99026d467b1aa973ed1cc50b67af36655bd33874361a81c0\",\"em\":\"2aa36b830def30c3d86c5a426e2f0138669a5f07813596f56b1b07b248a95b6d\",\"ph\":\"dbff5341acad5e2a58db4efd5e72e2d9a0a843a28e02b1183c68162d0a3a3de6\",\"ln\":\"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08\",\"fn\":\"5f3731b52ad0fb2f820b91495eb9961aebcbbc79d5881e5a26a382e694b9ccc0\",\"client_ip_address\":\"117.219.65.211\",\"client_user_agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\"},\"event_name\":\"Lead\",\"event_time\":1703171697,\"event_source_url\":\"https://www.redlighthealthstar.com/order-form-591807531683320674934?cf_uvid=dd3b917c7ede868ba450b0d13fd60466\",\"event_id\":\"5a6f81a6-63f2-4731-8543-69c3907f4334\",\"action_source\":\"website\",\"custom_data\":{\"currency\":\"USD\"}}"
],
"test_event_code": "TEST81471"
},
"JSON": {},
"JSON_ARRAY": {}
},
"type": "REST",
"files": {},
"method": "POST",
"params": {},
"userId": "",
"headers": {},
"version": "1",
"endpoint": "https://graph.facebook.com/v18.0/583035036163206/events?access_token=(removed access token)"
}miniature-iron-53243
12/22/2023, 1:57 PMmillions-activity-52391
12/27/2023, 2:18 PMshy-kite-21035
12/27/2023, 2:20 PMrudderanalytics.identify(userId, {
first_name: inputValues['first_name'] || '',
last_name: inputValues['last_name'] || '',
phone: inputValues['phone'] || '',
email: inputValues['email'] || '',
fbp: fbpLocalStorage || '',
fbc: fbclid || ''
});
This should save the fbp and fbc in the traits object and send them to subsequent events.thankful-monkey-19954
01/02/2024, 4:19 PMmillions-activity-52391
01/02/2024, 4:22 PMthankful-monkey-19954
01/02/2024, 4:27 PM