最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - FB pixel. Get client id (fbp) - Stack Overflow

programmeradmin9浏览0评论

We wanna push data in FB Pixel like in Google Analytics.
By this link =&ev=test_event I can push data in Pixel but it will just event, for link this event and client, need client_id (in pixel it's call fbp, if I don't make mistake).

What we want to do in general:
JS have to get pixel client_id, then send by ajax to our server, server will make some analyze, then send data to FB pixel.
So, I have to get pixel client_id on JS.
For example, in GA you can get client_id by this code: ga.getAll()[0].get('clientId');

Example, send to Pixel by JS

fbq('track', 'AddToCart', {
    content_name: 'Really Fast Running Shoes', 
    content_category: 'Apparel & Accessories > Shoes',
    content_ids: ['1234'],
    content_type: 'product',
    value: 4.99,
    currency: 'USD' 
});

in "Network" I see, that send
/?id=pixel_id&ev=AddToCart&dl=https%3A%2F%2Flusido.000webhostapp%2Ffor_test%2FFB_pixel%2F&rl=&if=false&ts=1568822256426&cd[content_name]=Really%20Fast%20Running%20Shoes&cd[content_category]=Apparel%20%26%20Accessories%20%3E%20Shoes&cd[content_ids]=%5B%221234%22%5D&cd[content_type]=product&cd[value]=4.99&cd[currency]=USD&sw=1920&sh=1080&v=2.9.4&r=stable&ec=3&o=30&fbp=fb.1.1568641299934.291266893&it=1568732325055&coo=false&rqm=GET
...&fbp=fb.1.1568641299934.291266893... request already have fbp.

So, question: How can I get pixel client_id?

We wanna push data in FB Pixel like in Google Analytics.
By this link https://www.facebook./tr?id=&ev=test_event I can push data in Pixel but it will just event, for link this event and client, need client_id (in pixel it's call fbp, if I don't make mistake).

What we want to do in general:
JS have to get pixel client_id, then send by ajax to our server, server will make some analyze, then send data to FB pixel.
So, I have to get pixel client_id on JS.
For example, in GA you can get client_id by this code: ga.getAll()[0].get('clientId');

Example, send to Pixel by JS

fbq('track', 'AddToCart', {
    content_name: 'Really Fast Running Shoes', 
    content_category: 'Apparel & Accessories > Shoes',
    content_ids: ['1234'],
    content_type: 'product',
    value: 4.99,
    currency: 'USD' 
});

in "Network" I see, that send
https://www.facebook./tr/?id=pixel_id&ev=AddToCart&dl=https%3A%2F%2Flusido.000webhostapp.%2Ffor_test%2FFB_pixel%2F&rl=&if=false&ts=1568822256426&cd[content_name]=Really%20Fast%20Running%20Shoes&cd[content_category]=Apparel%20%26%20Accessories%20%3E%20Shoes&cd[content_ids]=%5B%221234%22%5D&cd[content_type]=product&cd[value]=4.99&cd[currency]=USD&sw=1920&sh=1080&v=2.9.4&r=stable&ec=3&o=30&fbp=fb.1.1568641299934.291266893&it=1568732325055&coo=false&rqm=GET
...&fbp=fb.1.1568641299934.291266893... request already have fbp.

So, question: How can I get pixel client_id?

Share Improve this question asked Sep 19, 2019 at 10:18 OlehOleh 412 silver badges5 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8
function getFbClientId() {
  let result = /_fbp=(fb\.1\.\d+\.\d+)/.exec(window.document.cookie);
  if (!(result && result[1])) {
    return null;
  }
  return result[1];
}
getFbClientId();
window.fbq
.getState()
.pixels.forEach(e => {
     console.log("FB pixel ID", e.id);
});
发布评论

评论列表(0)

  1. 暂无评论