Hi I have been trying to send fbc and fnp values t...
# support
m
Hi I have been trying to send fbc and fnp values to Facebook Conversions via CAPI but even after passing in the standard Rudderstack format it does not show in the payload
m
Hey There! 👋 Your message has been received by the RudderStack team. Our standard customer support hours are 9-6 PM EST, but we will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
m
This is the code on the website
Copy code
function 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 '';
}
CC: @thankful-monkey-19954
✅ 1
m
Hi Joyan can you share a sample event both from source and destination.
m
Identify Call Payload from Javascript Source
Copy code
{
  "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"
}
Lead track call
Copy code
{
  "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"
}
FB Conversions Payload
Copy code
{
  "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)"
}
Hi is there any progress here?
m
Hi Joyan, sorry for the delay since it is Christmas time and most of the folks are on leave. So I see that in the identify call context you have added the fbp and fbc values but you are actually sending them in the options object. identify(<Name>, <Properties>, <Options>) You should send it in the properties object since it is part of the user traits. Can you try this instead, like this.
s
Copy code
rudderanalytics.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.
t
Hi @shy-kite-21035 Thanks for sharing this solution. We tried this but it seems to not work out as expected. We checked the RDS documentation and it states that fbc & fbp should be passed as context data, can you please guide us on this. CC - @miniature-iron-53243
m
Can we have a call on this. I am available tomorrow. You can setup a call here
t
Thanks! Call scheduled ✅