Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Facebook Conversions API (Node.js)

Facebook Conversions API

Conversions API.

facebook-nodejs-business-sdk

facebook-nodejs-business-sdk:

npm install facebook-nodejs-business-sdk

Content

const { Content } = require('facebook-nodejs-business-sdk');

const content = new Content();

content.setBrand();
content.Category();
content.setDeliveryCategory();
content.setDescription();
content.setId();
content.setItemPrice();
content.setQuantity();
content.setTitle();

CustomData

const { CustomData } = require('facebook-nodejs-business-sdk');

const customData = new CustomData();

customData.setContentCategory();
customData.setContentIds();
customData.setContentName();
customData.setContentType();
customData.setContents();
customData.setCurrency();
customData.setCustomProperties();
customData.setDeliveryCategory();
customData.setItemNumber();
customData.setNumItems();
customData.setOrderId();
customData.setPredictedLtv();
customData.setSearchString();
customData.setStatus();
customData.setValue();

DeliveryCategory

const { DeliveryCategory } = require('facebook-nodejs-business-sdk');

DeliveryCategory.IN_STORE; // 'in_store'
DeliveryCategory.CURBSIDE; // 'curbside'
DeliveryCategory.HOME_DELIVERY; // 'home_delivery'

EventRequest

const { EventRequest } = require('facebook-nodejs-business-sdk');

const accessToken = process.env.FB_CONVERSIONS_ACCESS_TOKEN;
const pixelId = process.env.FB_PIXEL_ID;

const eventRequest = new EventRequest(accessToken, pixelId);

const eventsData = [serverEvent]; // new ServerEvent()
eventsRequest.setEvents(eventsData);
eventRequest.execute().then(console.log).catch(console.error);

UserData

const { UserData } = require('facebook-nodejs-business-sdk');

const userData = new UserData();

userData.setCities();
userData.setCity();
userData.setClientIpAddress();
userData.setClientUserAgent();
userData.setCountries();
userData.setCountry();
userData.setDateOfBirth();
userData.setDatesOfBirth();
userData.setDobd();
userData.setDobm();
userData.setDoby();
userData.setEmail();
userData.setEmails();
userData.setExternalId();
userData.setExternalIds();
userData.setF5First();
userData.setF5Last();
userData.setFbLoginId();
userData.setFbc();
userData.setFbp();
userData.setFi();
userData.setFirstName();
userData.setFirstNames();
userData.setGender();
userData.setGenders();
userData.setLastName();
userData.setLastNames();
userData.setLeadId();
userData.setPhone();
userData.setPhones();
userData.setState();
userData.setStates();
userData.setSubscriptionId();
userData.setZip();
userData.setZips();

ServerEvent

const { ServerEvent } = require('facebook-nodejs-business-sdk');

const serverEvent = new ServerEvent();

serverEvent.setActionSource();
serverEvent.setCustomData();
serverEvent.setDataProcessingOptions();
serverEvent.setDataProcessingOptionsCountry();
serverEvent.setDataProcessingOptionsState();
serverEvent.setEventId();
serverEvent.setEventName();
serverEvent.setEventSourceUrl();
serverEvent.setEventTime();
serverEvent.setOptOut();
serverEvent.setUserData();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment