Skip to content

Commit

Permalink
feat: update facebook destinations API version to v18.0 (#2828)
Browse files Browse the repository at this point in the history
* feat: update facebook destinations API version to v18.0

* feat: updated fb_pixel tests to pick version dynamically from config.js

* feat: updated fb tests to pick version dynamically from config.js

* feat: updated fb_custom_audience tests to pick version dynamically from config.js
  • Loading branch information
sandeepdsvs authored Nov 29, 2023
1 parent 91d4cd1 commit 3127a1c
Show file tree
Hide file tree
Showing 16 changed files with 479 additions and 448 deletions.
3 changes: 3 additions & 0 deletions src/v0/destinations/facebook_pixel/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { getMappingConfig } = require('../../util');

const VERSION = 'v18.0';

const CONFIG_CATEGORIES = {
USERDATA: {
standard: false,
Expand Down Expand Up @@ -106,6 +108,7 @@ const STANDARD_ECOMM_EVENTS_TYPE = [
];

module.exports = {
VERSION,
CONFIG_CATEGORIES,
MAPPING_CONFIG,
ACTION_SOURCES_VALUES,
Expand Down
3 changes: 2 additions & 1 deletion src/v0/destinations/facebook_pixel/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const moment = require('moment');
const { InstrumentationError, ConfigurationError } = require('@rudderstack/integrations-lib');
const stats = require('../../../util/stats');
const {
VERSION,
CONFIG_CATEGORIES,
MAPPING_CONFIG,
FB_PIXEL_DEFAULT_EXCLUSION,
Expand Down Expand Up @@ -65,7 +66,7 @@ const responseBuilderSimple = (message, category, destination) => {
} = Config;
const integrationsObj = getIntegrationsObj(message, 'fb_pixel');

const endpoint = `https://graph.facebook.com/v17.0/${pixelId}/events?access_token=${accessToken}`;
const endpoint = `https://graph.facebook.com/${VERSION}/${pixelId}/events?access_token=${accessToken}`;

const userData = fetchUserData(
message,
Expand Down
3 changes: 3 additions & 0 deletions src/v0/destinations/fb/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fs = require('fs');
const path = require('path');

const VERSION = 'v18.0';

const getPath = (file) => path.resolve(__dirname, file);

const baseMapping = JSON.parse(fs.readFileSync(getPath('./data/FbAppBasicMapping.json')));
Expand All @@ -20,6 +22,7 @@ const eventPropToTypeMapping = JSON.parse(
);

module.exports = {
VERSION,
baseMapping,
eventNameMapping,
eventPropsMapping,
Expand Down
3 changes: 2 additions & 1 deletion src/v0/destinations/fb/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
} = require('../../util');

const {
VERSION,
baseMapping,
eventNameMapping,
eventPropsMapping,
Expand Down Expand Up @@ -250,7 +251,7 @@ function responseBuilderSimple(message, payload, destination) {

// "https://graph.facebook.com/v13.0/644748472345539/activities"

const endpoint = `https://graph.facebook.com/v17.0/${appID}/activities`;
const endpoint = `https://graph.facebook.com/${VERSION}/${appID}/activities`;

const response = defaultRequestConfig();
response.endpoint = endpoint;
Expand Down
4 changes: 2 additions & 2 deletions src/v0/destinations/fb_custom_audience/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BASE_URL = 'https://graph.facebook.com/v17.0';
const BASE_URL = 'https://graph.facebook.com/v18.0';

function getEndPoint(audienceId) {
return `${BASE_URL}/${audienceId}/users`;
Expand Down Expand Up @@ -93,7 +93,7 @@ const subTypeFields = [
// const MAX_USER_COUNT = 500; (using from destination definition)
const USER_ADD = 'add';
const USER_DELETE = 'remove';
/* No official Documentation is available for this but using trial
/* No official Documentation is available for this but using trial
and error method we found that 65000 bytes is the maximum payload allowed size but we are 60000 just to be sure batching is done properly
*/
const maxPayloadSize = 60000; // bytes
Expand Down
29 changes: 11 additions & 18 deletions test/integrations/destinations/facebook_pixel/dataDelivery/data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { VERSION } from '../../../../../src/v0/destinations/facebook_pixel/config';

export const data = [
{
name: 'facebook_pixel',
Expand All @@ -24,8 +26,7 @@ export const data = [
userId: '',
headers: {},
version: '1',
endpoint:
'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=invalid_access_token',
endpoint: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=invalid_access_token`,
params: {
destination: 'facebook_pixel',
},
Expand Down Expand Up @@ -89,8 +90,7 @@ export const data = [
userId: '',
headers: {},
version: '1',
endpoint:
'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=my_access_token',
endpoint: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=my_access_token`,
params: {
destination: 'facebook_pixel',
},
Expand Down Expand Up @@ -139,8 +139,7 @@ export const data = [
userId: '',
headers: {},
version: '1',
endpoint:
'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=invalid_timestamp_correct_access_token',
endpoint: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=invalid_timestamp_correct_access_token`,
params: {
destination: 'facebook_pixel',
},
Expand Down Expand Up @@ -209,8 +208,7 @@ export const data = [
userId: '',
headers: {},
version: '1',
endpoint:
'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=throttled_valid_access_token',
endpoint: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=throttled_valid_access_token`,
params: {
destination: 'facebook_pixel',
},
Expand Down Expand Up @@ -274,8 +272,7 @@ export const data = [
userId: '',
headers: {},
version: '1',
endpoint:
'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=invalid_account_id_valid_access_token',
endpoint: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=invalid_account_id_valid_access_token`,
params: {
destination: 'facebook_pixel',
},
Expand Down Expand Up @@ -342,8 +339,7 @@ export const data = [
userId: '',
headers: {},
version: '1',
endpoint:
'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=not_found_access_token',
endpoint: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=not_found_access_token`,
params: {
destination: 'facebook_pixel',
},
Expand Down Expand Up @@ -411,8 +407,7 @@ export const data = [
userId: '',
headers: {},
version: '1',
endpoint:
'https://graph.facebook.com/v17.0/1234567891234570/events?access_token=valid_access_token',
endpoint: `https://graph.facebook.com/${VERSION}/1234567891234570/events?access_token=valid_access_token`,
},
method: 'POST',
},
Expand Down Expand Up @@ -477,8 +472,7 @@ export const data = [
userId: '',
headers: {},
version: '1',
endpoint:
'https://graph.facebook.com/v17.0/1234567891234571/events?access_token=valid_access_token',
endpoint: `https://graph.facebook.com/${VERSION}/1234567891234571/events?access_token=valid_access_token`,
},
method: 'POST',
},
Expand Down Expand Up @@ -543,8 +537,7 @@ export const data = [
userId: '',
headers: {},
version: '1',
endpoint:
'https://graph.facebook.com/v17.0/1234567891234572/events?access_token=valid_access_token_unhandled_response',
endpoint: `https://graph.facebook.com/${VERSION}/1234567891234572/events?access_token=valid_access_token_unhandled_response`,
},
method: 'POST',
},
Expand Down
19 changes: 10 additions & 9 deletions test/integrations/destinations/facebook_pixel/network.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { data } from './dataDelivery/data';
import { getFormData } from '../../../../src/adapters/network';
import { VERSION } from '../../../../src/v0/destinations/facebook_pixel/config';

export const networkCallsData = [
{
httpReq: {
url: 'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=invalid_access_token',
url: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=invalid_access_token`,
data: getFormData(data[0].input.request.body.body.FORM).toString(),
params: { destination: 'facebook_pixel' },
headers: { 'User-Agent': 'RudderLabs' },
Expand All @@ -24,7 +25,7 @@ export const networkCallsData = [
},
{
httpReq: {
url: 'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=invalid_timestamp_correct_access_token',
url: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=invalid_timestamp_correct_access_token`,
data: getFormData(data[2].input.request.body.body.FORM).toString(),
params: { destination: 'facebook_pixel' },
headers: { 'User-Agent': 'RudderLabs' },
Expand All @@ -49,7 +50,7 @@ export const networkCallsData = [
},
{
httpReq: {
url: 'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=throttled_valid_access_token',
url: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=throttled_valid_access_token`,
data: getFormData(data[3].input.request.body.body.FORM).toString(),
params: { destination: 'facebook_pixel' },
headers: { 'User-Agent': 'RudderLabs' },
Expand All @@ -69,7 +70,7 @@ export const networkCallsData = [
},
{
httpReq: {
url: 'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=invalid_account_id_valid_access_token',
url: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=invalid_account_id_valid_access_token`,
data: getFormData(data[4].input.request.body.body.FORM).toString(),
params: { destination: 'facebook_pixel' },
headers: { 'User-Agent': 'RudderLabs' },
Expand All @@ -91,7 +92,7 @@ export const networkCallsData = [
},
{
httpReq: {
url: 'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=not_found_access_token',
url: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=not_found_access_token`,
data: getFormData(data[5].input.request.body.body.FORM).toString(),
params: { destination: 'facebook_pixel' },
headers: { 'User-Agent': 'RudderLabs' },
Expand All @@ -112,7 +113,7 @@ export const networkCallsData = [
},
{
httpReq: {
url: 'https://graph.facebook.com/v17.0/1234567891234570/events?access_token=valid_access_token',
url: `https://graph.facebook.com/${VERSION}/1234567891234570/events?access_token=valid_access_token`,
data: getFormData(data[6].input.request.body.body.FORM).toString(),
params: { destination: 'facebook_pixel' },
headers: { 'User-Agent': 'RudderLabs' },
Expand All @@ -133,7 +134,7 @@ export const networkCallsData = [
},
{
httpReq: {
url: 'https://graph.facebook.com/v17.0/1234567891234571/events?access_token=valid_access_token',
url: `https://graph.facebook.com/${VERSION}/1234567891234571/events?access_token=valid_access_token`,
data: getFormData(data[7].input.request.body.body.FORM).toString(),
params: { destination: 'facebook_pixel' },
headers: { 'User-Agent': 'RudderLabs' },
Expand All @@ -154,7 +155,7 @@ export const networkCallsData = [
},
{
httpReq: {
url: 'https://graph.facebook.com/v17.0/1234567891234572/events?access_token=valid_access_token_unhandled_response',
url: `https://graph.facebook.com/${VERSION}/1234567891234572/events?access_token=valid_access_token_unhandled_response`,
data: getFormData(data[8].input.request.body.body.FORM).toString(),
params: { destination: 'facebook_pixel' },
headers: { 'User-Agent': 'RudderLabs' },
Expand All @@ -175,7 +176,7 @@ export const networkCallsData = [
},
{
httpReq: {
url: 'https://graph.facebook.com/v17.0/1234567891234567/events?access_token=my_access_token',
url: `https://graph.facebook.com/${VERSION}/1234567891234567/events?access_token=my_access_token`,
data: getFormData(data[1].input.request.body.body.FORM).toString(),
params: { destination: 'facebook_pixel' },
headers: { 'User-Agent': 'RudderLabs' },
Expand Down
Loading

0 comments on commit 3127a1c

Please sign in to comment.