如何在一个组件中使用多个 ReactPixel.track('abc')?

How to use multiple ReactPixel.track('abc') inside one component?

我有一个组件,我必须在其上添加两个 ReactPixel.track('abc') 和 ReactPixel.track('cba'),我该如何实现?我只需要添加一个 ReactPixe.init('id') 还是两个?这是一个代码示例:

componentDidMount() {
  const options = {
    autoConfig: false,
  };



  ReactPixel.init('123123', options);
  ReactPixel.pageView();
  ReactPixel.track('abc');
  ReactPixel.track('cba');

}

您不需要在每个页面上添加多个 React init。 只需将它添加到您的 App.js(如果您使用 create-react-app)。 * 使用前请先启动。

ReactPixel.init('123123', options);

如果您需要获取整个应用的页面浏览量详细信息,您需要在入门级使用下面的 code.function。(我更喜欢在 init 函数之后)

ReactPixel.pageView();

没有魔法。它只是调用 Facebook 提供给您的相同功能。 fbq('track', 'PageView');

您可以在函数中使用跟踪代码。例如注册成功后可以创建这个track code。

ReactPixel.track('abc',{#data object goes here});

这是Facebook给出的例子。

fbq('track', 'Purchase',
  // begin parameter object data
  {
    value: 115.00,
    currency: 'USD',
    contents: [
      {
        id: '301',
        quantity: 1,
        item_price: 85.00
      },
      {
        id: '401',
        quantity: 2,
        item_price: 15.00
      }],
    content_type: 'product'
  }
  // end parameter object data
);

您可以像这样将相同的功能与 react-facebook-pixel 包装器一起使用。

ReactPixel.track('abc',{#data object goes here});

跟踪自定义事件

You can track custom events by calling the pixel's fbq('trackCustom') function, with your custom event name and (optionally) a JSON object as its parameters. Just like standard events, you can call the fbq('trackCustom') function anywhere between your webpage's opening and closing tags, either when your page loads, or when a visitor performs an action like clicking a button.

For example, let's say you wanted to track visitors who share a promotion in order to get a discount. You could track them using a custom event like this:

fbq('trackCustom', 'ShareDiscount', {promotion: 'share_discount_10%'});

您可以像这样使用 React 包装器跟踪自定义事件

ReactPixel.trackCustom(#title_of_event,#data_object);

如果您需要更多地了解此 react-facebook-pixel 所做的事情。您可以阅读包的代码。 https://github.com/zsajjad/react-facebook-pixel/blob/master/src/index.js

Facebook 文档:https://developers.facebook.com/docs/facebook-pixel/implementation/conversion-tracking#advanced_match