Skip to content

Commit 809d2cf

Browse files
authored
Update appsflyer methods response (#134)
1 parent 7db997d commit 809d2cf

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/plugins/appsflyer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppsFlyer } from '../types/appsflyer.js';
2-
import { addCommand } from '../utils/index.js';
2+
import { addCommandCallback } from '../utils/index.js';
33
import { createListener } from '../utils/listener.js';
44

55
/**
@@ -13,8 +13,8 @@ const appsflyer = {
1313
* @param eventName - The name of the event to be tracked.
1414
* @param eventValues - Key-value pairs containing event metadata.
1515
*/
16-
logEvent: function (eventName: string, eventValues: any) {
17-
addCommand('median://appsflyer/logEvent', { eventName, eventValues });
16+
logEvent: function (eventName: string, eventValues?: Record<string, any>) {
17+
return addCommandCallback<AppsFlyer.LogEventResponse>('median://appsflyer/logEvent', { eventName, eventValues });
1818
},
1919

2020
/**
@@ -24,7 +24,7 @@ const appsflyer = {
2424
* @param userId - Unique identifier for the current user.
2525
*/
2626
setCustomerUserId: function (userId: string) {
27-
addCommand('median://appsflyer/setCustomerUserId', { userId });
27+
return addCommandCallback<AppsFlyer.SetCustomerUserIdResponse>('median://appsflyer/setCustomerUserId', { userId });
2828
},
2929

3030
/**

src/types/appsflyer.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export namespace AppsFlyer {
22
export type ConversionData = Record<string, any> & {
33
af_message?: string;
44
af_status?: string;
5-
error?: string;
5+
error?: { code?: string; description?: string };
66
install_time?: string;
77
is_first_launch?: boolean;
88
};
@@ -18,13 +18,24 @@ export namespace AppsFlyer {
1818
clickEvent?: string;
1919
clickHTTPReferrer?: string;
2020
deeplinkValue?: string;
21+
error?: { code?: string; description?: string };
2122
isDeferred: boolean;
2223
matchType?: string;
2324
mediaSource?: string;
2425
};
2526

2627
export type SdkStartResponse = {
27-
error?: string;
28+
error?: { code?: string; description?: string };
29+
success: boolean;
30+
};
31+
32+
export type LogEventResponse = {
33+
error?: { code?: string; description?: string };
34+
success: boolean;
35+
};
36+
37+
export type SetCustomerUserIdResponse = {
38+
error?: { code?: string; description?: string };
2839
success: boolean;
2940
};
3041
}

src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function addCommandCallback<T = AnyData>(
8282
params.callback = tempFunctionName;
8383
return new Promise(function (resolve, reject) {
8484
(window[tempFunctionName as AnyData] as AnyData) = function (data: T) {
85-
if (data && typeof data === 'object' && 'error' in data && typeof data.error === 'string') {
85+
if (data && typeof data === 'object' && 'error' in data) {
8686
reject(data);
8787
} else {
8888
resolve(data);

0 commit comments

Comments
 (0)