| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- // FacebookPixel.js
- import React, { useEffect } from "react";
- export const fb_setPixelID = (pixelID,ex_id) => {
- if (!pixelID) return;
- const initFbq=(f, b, e, v, n, t, s)=>{
- if (f.fbq) return;
- n = f.fbq = function () {
- n.callMethod
- ? n.callMethod.apply(n, arguments)
- : n.queue.push(arguments);
- };
- if (!f._fbq) f._fbq = n;
- n.push = n;
- n.loaded = !0;
- n.version = "2.0";
- n.queue = [];
- t = b.createElement(e);
- t.async = !0;
- t.src = v;
- s = b.getElementsByTagName(e)[0];
- s.parentNode.insertBefore(t, s);
- }
- initFbq(
- window,
- document,
- "script",
- "https://connect.facebook.net/en_US/fbevents.js"
- )
- // window.fbq('set', 'autoConfig', false, pixelID);
- if(!!ex_id){
- window.fbq("init", pixelID, {'external_id': ex_id});
- }else{
- window.fbq("init", pixelID);
- }
- window.fbq("track", "PageView");
- };
- const standardEvents = [
- 'PageView',
- 'ViewContent',
- 'Search',
- 'AddToCart',
- 'AddToWishlist',
- 'InitiateCheckout',
- 'AddPaymentInfo',
- 'Purchase',
- 'Lead',
- 'CompleteRegistration'
- ];
- // fbPixel.js
- export const fb_trackPageView = () => {
- if (window.fbq) {
- window.fbq('track', 'PageView');
- }
- };
- /**
- * fbq('trackCustom', "firstpayD0", {external_id: data.udid})
- * @param eventName
- * @param params
- */
- export const fb_trackEvent = (eventName, params) => {
- if (window.fbq) {
- if (standardEvents.includes(eventName)) {
- window.fbq('track', eventName, params);
- }else{
- window.fbq('trackCustom', eventName, params);
- }
- }
- };
|