Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add v3 api support to appsflyer #3412

Merged
merged 7 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/v0/destinations/af/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const Event = {
};

const ENDPOINT = 'https://api2.appsflyer.com/inappevent/';
const ENDPOINT_V2 = 'https://api3.appsflyer.com/inappevent/';

const mappingConfig = getMappingConfig(ConfigCategory, __dirname);

Expand All @@ -69,6 +70,7 @@ events.forEach((event) => {
module.exports = {
ConfigCategory,
ENDPOINT,
ENDPOINT_V2,
Event,
mappingConfig,
nameToEventMap,
Expand Down
44 changes: 36 additions & 8 deletions src/v0/destinations/af/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,32 @@ const {
simpleProcessRouterDest,
} = require('../../util');

const { Event, ENDPOINT, ConfigCategory, mappingConfig, nameToEventMap } = require('./config');
const {
Event,
ENDPOINT,
ENDPOINT_V2,
ConfigCategory,
mappingConfig,
nameToEventMap,
} = require('./config');
const { JSON_MIME_TYPE } = require('../../util/constant');

function responseBuilderSimple(payload, message, destination) {
const { androidAppId, appleAppId } = destination.Config;
const { androidAppId, appleAppId, sharingFilter, devKey, s2sKey, authVersion } =
destination.Config;
let endpoint;
const os = get(message, 'context.os.name');
// if ((os && os.toLowerCase() === "android") || (os && isAppleFamily(os))){
// if()
// }

const finalEndPoint =
isDefinedAndNotNull(authVersion) && authVersion === 'v2' ? ENDPOINT_V2 : ENDPOINT;

if (os && os.toLowerCase() === 'android' && androidAppId) {
endpoint = `${ENDPOINT}${androidAppId}`;
endpoint = `${finalEndPoint}${androidAppId}`;
} else if (os && isAppleFamily(os) && appleAppId) {
endpoint = `${ENDPOINT}id${appleAppId}`;
endpoint = `${finalEndPoint}id${appleAppId}`;
} else {
throw new ConfigurationError(
'os name is required along with the respective appId eg. (os->android & Android App Id is required) or (os->ios & Apple App Id is required)',
Expand Down Expand Up @@ -87,16 +99,19 @@ function responseBuilderSimple(payload, message, destination) {
updatedPayload.bundleIdentifier = bundleIdentifier;
}

const { sharingFilter, devKey } = destination.Config;
// const { sharingFilter, devKey } = destination.Config;
if (isDefinedAndNotNullAndNotEmpty(sharingFilter)) {
updatedPayload.sharing_filter = sharingFilter;
}

const finalAuthentication =
isDefinedAndNotNull(authVersion) && authVersion === 'v2' ? s2sKey : devKey;

const response = defaultRequestConfig();
response.endpoint = endpoint;
response.headers = {
'Content-Type': JSON_MIME_TYPE,
authentication: devKey,
authentication: finalAuthentication,
};
response.method = defaultPostRequestConfig.requestMethod;
response.body.JSON = removeUndefinedAndNullValues(updatedPayload);
Expand Down Expand Up @@ -203,6 +218,19 @@ function processEventTypeTrack(message, config) {
}

function processSingleMessage(message, destination) {
const { devKey, s2sKey, authVersion, useRichEventName } = destination.Config;

if (!isDefinedAndNotNull(authVersion) && !isDefinedAndNotNull(devKey)) {
throw new ConfigurationError('No authentication key is present. Aborting.');
}

if (isDefinedAndNotNull(authVersion) && authVersion === 'v2' && !isDefinedAndNotNull(s2sKey)) {
throw new ConfigurationError('s2s key is mandatory for v2 authorization. Aborting.');
}

if (isDefinedAndNotNull(authVersion) && authVersion === 'v1' && !isDefinedAndNotNull(devKey)) {
throw new ConfigurationError('dev key is mandatory for v1 authorization. Aborting.');
}
const messageType = message.type.toLowerCase();
let payload;
switch (messageType) {
Expand All @@ -212,7 +240,7 @@ function processSingleMessage(message, destination) {
}
case EventType.SCREEN: {
let eventName;
if (destination.Config.useRichEventName === true) {
if (useRichEventName === true) {
eventName = `Viewed ${
message.name || message.event || get(message, 'properties.name') || ''
} Screen`;
Expand All @@ -224,7 +252,7 @@ function processSingleMessage(message, destination) {
}
case EventType.PAGE: {
let eventName;
if (destination.Config.useRichEventName === true) {
if (useRichEventName === true) {
eventName = `Viewed ${message.name || get(message, 'properties.name') || ''} Page`;
} else {
eventName = EventType.PAGE;
Expand Down
Loading
Loading