@nurliman/facebook-conversion-api
Advanced tools
Comparing version 3.0.2 to 3.1.0
@@ -1,2 +0,4 @@ | ||
import { UserData, Content } from 'facebook-nodejs-business-sdk'; | ||
import * as facebook_nodejs_business_sdk_src_objects_serverside_event_response from 'facebook-nodejs-business-sdk/src/objects/serverside/event-response'; | ||
import Content from 'facebook-nodejs-business-sdk/src/objects/serverside/content'; | ||
import UserData from 'facebook-nodejs-business-sdk/src/objects/serverside/user-data'; | ||
@@ -8,2 +10,3 @@ declare class FacebookConversionAPI { | ||
fbc: string | null; | ||
externalId: string | null; | ||
userData: UserData & Record<string, any>; | ||
@@ -17,3 +20,3 @@ contents: (Content & Record<string, any>)[]; | ||
*/ | ||
constructor(accessToken: string, pixelId: string, emails: Array<string> | null, phones: Array<string> | null, clientIpAddress: string, clientUserAgent: string, fbp: string | null, fbc: string | null, testEventCode?: string, debug?: boolean); | ||
constructor(accessToken: string, pixelId: string, emails: Array<string> | null, phones: Array<string> | null, clientIpAddress: string, clientUserAgent: string, fbp: string | null, fbc: string | null, externalId: string | null, testEventCode?: string, debug?: boolean); | ||
/** | ||
@@ -31,3 +34,3 @@ * Add product to contents array. | ||
eventId?: string; | ||
}): Promise<any>; | ||
}): Promise<facebook_nodejs_business_sdk_src_objects_serverside_event_response.default>; | ||
setContentType(contentType: string): this; | ||
@@ -34,0 +37,0 @@ /** |
'use strict'; | ||
var facebookNodejsBusinessSdk = require('facebook-nodejs-business-sdk'); | ||
var b = require('facebook-nodejs-business-sdk/src/objects/serverside/content'); | ||
var v = require('facebook-nodejs-business-sdk/src/objects/serverside/user-data'); | ||
function o(n){return !isNaN(parseFloat(n))&&isFinite(n)}function c(n){return o(n)?(n=parseFloat(n),n|0):null}var l=class{constructor(s,r,e,t,i,u,a,g,f,d=!1){this.constentType="product";this.accessToken=s,this.pixelId=r,this.fbp=a,this.fbc=g,this.debug=d,this.testEventCode=f,this.userData=new facebookNodejsBusinessSdk.UserData,u&&this.userData.setClientUserAgent(u),Array.isArray(e)&&e.length&&this.userData.setEmails(e),typeof e=="string"&&e&&this.userData.setEmails([e]),Array.isArray(t)&&t.length&&this.userData.setPhones(t),(typeof t=="string"||typeof t=="number")&&t&&this.userData.setPhones([t]),u&&(this.userData=this.userData.setClientIpAddress(i)),a&&(this.userData=this.userData.setFbp(a)),g&&(this.userData=this.userData.setFbc(g)),this.contents=[],this.debug&&console.log(`User Data: ${JSON.stringify(this.userData)} | ||
`);}addProduct(s,r,e){if(!s)throw new Error("Product ID is required");let t=new facebookNodejsBusinessSdk.Content().setId(s).setBrand("Knitto");return o(r)&&(t=t.setQuantity(c(r))),o(e)&&(t=t.setItemPrice(c(e))),this.contents.push(t),this.debug&&console.log(`Add To Cart: ${JSON.stringify(this.contents)} | ||
`),this}async sendEvent(s,r,e,t){let i=new facebookNodejsBusinessSdk.EventRequest(this.accessToken,this.pixelId).setEvents([this.getEventData(s,r,e,t)]);return this.testEventCode&&i.setTestEventCode(this.testEventCode),this.contents=[],this.debug&&console.log(`Event Request: ${JSON.stringify(i)} | ||
`),await i.execute()}setContentType(s){return this.constentType=s,this}getEventData(s,r,e,t){let i=Math.floor(new Date/1e3);return new facebookNodejsBusinessSdk.ServerEvent().setEventName(s).setEventTime(i).setEventId(t==null?void 0:t.eventId).setUserData(this.userData).setCustomData(new facebookNodejsBusinessSdk.CustomData().setContents(this.contents).setContentType(this.constentType).setCurrency(e==null?void 0:e.currency).setValue(e==null?void 0:e.value)).setEventSourceUrl(r).setActionSource("website")}},N=l; | ||
function o(e){return !isNaN(parseFloat(e))&&isFinite(e)}function f(e){return o(e)?(e=parseFloat(e),e|0):null}var c=class{constructor(s,l,n,t,i,u,r,a,g,h,d=!1){this.constentType="product";this.accessToken=s,this.pixelId=l,this.fbp=r,this.fbc=a,this.externalId=g,this.debug=d,this.testEventCode=h,this.userData=new v(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null),u&&this.userData.setClientUserAgent(u),Array.isArray(n)&&n.length&&this.userData.setEmails(n),typeof n=="string"&&n&&this.userData.setEmails([n]),Array.isArray(t)&&t.length&&this.userData.setPhones(t),(typeof t=="string"||typeof t=="number")&&t&&this.userData.setPhones([t]),u&&(this.userData=this.userData.setClientIpAddress(i)),r&&(this.userData=this.userData.setFbp(r)),a&&(this.userData=this.userData.setFbc(a)),g&&(this.userData=this.userData.setExternalId(g)),this.contents=[],this.debug&&console.log(`User Data: ${JSON.stringify(this.userData)} | ||
`);}addProduct(s,l,n){if(!s)throw new Error("Product ID is required");let t=new b(s,null,null,null,null,"Knitto",null,null);return o(l)&&(t=t.setQuantity(f(l))),o(n)&&(t=t.setItemPrice(f(n))),this.contents.push(t),this.debug&&console.log(`Add To Cart: ${JSON.stringify(this.contents)} | ||
`),this}async sendEvent(s,l,n,t){let i=new facebookNodejsBusinessSdk.EventRequest(this.accessToken,this.pixelId).setEvents([this.getEventData(s,l,n,t)]);return this.testEventCode&&i.setTestEventCode(this.testEventCode),this.contents=[],this.debug&&console.log(`Event Request: ${JSON.stringify(i)} | ||
`),await i.execute()}setContentType(s){return this.constentType=s,this}getEventData(s,l,n,t){var r;let i=Math.floor(new Date/1e3),u=new facebookNodejsBusinessSdk.CustomData(n==null?void 0:n.value,n==null?void 0:n.currency,null,null,null,this.contents,this.constentType,null,null,((r=this.contents)==null?void 0:r.length)||null,null,null,null,null,null);return new facebookNodejsBusinessSdk.ServerEvent(s,i,l,this.userData,u,t==null?void 0:t.eventId,null,"website",null,null,null)}},A=c; | ||
module.exports = N; | ||
module.exports = A; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@nurliman/facebook-conversion-api", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "Facebook Conversion API Wrapper for Node.js", | ||
@@ -25,2 +25,3 @@ "license": "ISC", | ||
"devDependencies": { | ||
"@types/facebook-nodejs-business-sdk": "^15.0.0", | ||
"@types/node": "16", | ||
@@ -27,0 +28,0 @@ "@typescript-eslint/eslint-plugin": "^5.42.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
25874
69
12