diff --git a/.migration_backup/package.json b/.migration_backup/package.json index 6d9520c6..975a852b 100644 --- a/.migration_backup/package.json +++ b/.migration_backup/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-plugin-appsflyer", - "version": "6.12.1", + "version": "6.13.0", "description": "Appsflyer SDK for NativeScript applications", "main": "appsflyer", "typings": "index.d.ts", diff --git a/README.md b/README.md index a9ecade5..4d609cfb 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ ## This plugin is built for -- iOS AppsFlyerSDK **v6.12.0** -- Android AppsFlyerSDK **v6.12.1** +- iOS AppsFlyerSDK **v6.13.0** +- Android AppsFlyerSDK **v6.13.0** ## Breaking Changes diff --git a/appsflyer.android.d.ts b/appsflyer.android.d.ts index 89d75d36..72e4992c 100644 --- a/appsflyer.android.d.ts +++ b/appsflyer.android.d.ts @@ -1,11 +1,17 @@ -import { InitSDKOptions, LogEventOptions } from './index'; -export declare const initSdk: (args: InitSDKOptions) => Promise; -export declare const logEvent: (args: LogEventOptions) => Promise; -export declare const setCustomerUserId: (userId: string) => Promise; -export declare const setAppInviteOneLink: (link: string) => Promise; -export declare const generateInviteUrl: (args: AppsFlyerLinkGeneratorArgs) => Promise; -export declare const stop: (isStopped: bool) => Promise; -export declare const setSharingFilter: (partners: Array) => Promise; -export declare const setSharingFilterForAllPartners: () => Promise; -export declare const _toHashMap: (obj: Object) => javautilHashMap; -export declare const _toValue: (val: any) => any; +import { InitSDKOptions, LogEventOptions, AppsFlyerLinkGeneratorArgs , AppsFlyerConsentArgs } from './index'; +declare const initSdk: (args: InitSDKOptions) => Promise; +declare const startSdk: () => void; +declare const logEvent: (args: LogEventOptions) => Promise; +declare const setCustomerUserId: (userId: string) => Promise; +declare const setAppInviteOneLink: (link: string) => Promise; +declare const generateInviteUrl: (args: AppsFlyerLinkGeneratorArgs) => Promise; +declare const enableTCFDataCollection: (shouldCollect: boolean) => Promise; +declare const setConsentData: (consent: AppsFlyerConsentArgs) => Promise; +declare const getAppsFlyerUID: () => string; +declare const stop: (isStopped: boolean) => Promise; +declare const setSharingFilter: (partners: Array) => Promise; +declare const setSharingFilterForAllPartners: () => Promise; +declare const _toHashMap: (obj: Object) => javautilHashMap; +declare const _toValue: (val: any) => any; +export { initSdk, startSdk, logEvent, stop, setCustomerUserId, setAppInviteOneLink, generateInviteUrl, getAppsFlyerUID, enableTCFDataCollection, setConsentData,setSharingFilter,setSharingFilterForAllPartners,_toHashMap ,_toValue}; + diff --git a/appsflyer.android.ts b/appsflyer.android.ts index 7dcaa239..1d3cd2f2 100644 --- a/appsflyer.android.ts +++ b/appsflyer.android.ts @@ -1,10 +1,7 @@ // @ts-nocheck -import { Application, Utils } from "@nativescript/core"; +import { Application, Utils } from "@nativescript/core"; -import { - InitSDKOptions, - LogEventOptions, -} from './index'; +import { InitSDKOptions, LogEventOptions } from "./index"; const stringSetToStringArray = Utils.ad.collections.stringSetToStringArray; @@ -12,323 +9,431 @@ let _isDebugLocal = false; let _appsFlyerConversionListener = undefined; let _appsFlyerRequestListener = undefined; -export const initSdk = function (args: InitSDKOptions) { - - return new Promise(function (resolve, reject) { - try { - if (typeof(com.appsflyer.AppsFlyerLib) !== "undefined") { - - const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); - - _isDebugLocal = args.isDebug; - - appsFlyerLibInstance.setDebugLog(_isDebugLocal); - - if (args.onConversionDataSuccess || args.onConversionDataFail) { +const initSdk = function (args: InitSDKOptions) { + return new Promise(function (resolve, reject) { + try { + if (typeof com.appsflyer.AppsFlyerLib !== "undefined") { + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + + _isDebugLocal = args.isDebug; + + appsFlyerLibInstance.setDebugLog(_isDebugLocal); + + if (args.onConversionDataSuccess || args.onConversionDataFail) { + try { + _appsFlyerConversionListener = + new com.appsflyer.AppsFlyerConversionListener({ + _gcdSuccessCallback: args.onConversionDataSuccess, + _gcdFailureCallback: args.onConversionDataFail, + _oaoaSuccessCallback: args.onAppOpenAttribution, + _oaoaFailureCallback: args.onAppOpenAttributionFailure, + + onConversionDataSuccess( + conversionData: java.util.Map + ): void { + if (!this._gcdSuccessCallback) { + return; + } + if (typeof this._gcdSuccessCallback === "function") { try { - _appsFlyerConversionListener = new com.appsflyer.AppsFlyerConversionListener({ - _gcdSuccessCallback: args.onConversionDataSuccess, - _gcdFailureCallback: args.onConversionDataFail, - _oaoaSuccessCallback: args.onAppOpenAttribution, - _oaoaFailureCallback: args.onAppOpenAttributionFailure, - - onConversionDataSuccess(conversionData: java.util.Map): void { - if (!this._gcdSuccessCallback) { - return; - } - if (typeof this._gcdSuccessCallback === 'function') { - try { - const data = {}; - for (const key of stringSetToStringArray(conversionData.keySet())) { - data[key] = conversionData.get(key); - } - this._gcdSuccessCallback(data); - printLogs("onConversionDataSuccess: " + JSON.stringify(args)); - } catch (e) { - printLogs(`onConversionDataSuccess Error: ${e}`); - } - } else { - printLogs(`onConversionDataSuccess: callback is not a function`); - } - }, - onConversionDataFail(error: string): void { - if (!this._gcdFailureCallback) { - return; - } - if (typeof this._gcdFailureCallback === 'function') { - try { - this._gcdFailureCallback(error); - printLogs("onConversionDataFail error: " + error); - } catch (e) { - printLogs(`onConversionDataFail Error: ${e}`); - } - } else { - printLogs("onConversionDataFail: callback is not a function"); - } - }, - onAttributionFailure(error: string): void { - if (!this._oaoaFailureCallback) { - return; - } - if (typeof this._oaoaFailureCallback === 'function') { - try { - this._oaoaFailureCallback(error); - printLogs("onAttributionFailure error: " + error); - } catch (e) { - printLogs(`onAttributionFailure Error: ${e}`); - } - } else { - printLogs("onAttributionFailure: callback is not a function"); - } - }, - onAppOpenAttribution(onAppOpenAttributionData: java.util.Map): void { - if (!this._oaoaSuccessCallback) { - return; - } - if (typeof this._oaoaSuccessCallback === 'function') { - try { - let data = {}; - for (const key of stringSetToStringArray(onAppOpenAttributionData.keySet())) { - data[key] = onAppOpenAttributionData.get(key); - } - - printLogs("onAppOpenAttribution: " + JSON.stringify(data)); - } catch (e) { - printLogs(`onAppOpenAttribution Error: ${e}`); - } - } else { - printLogs(`onAppOpenAttribution: callback is not a function`); - } - }, - }); + const data = {}; + for (const key of stringSetToStringArray( + conversionData.keySet() + )) { + data[key] = conversionData.get(key); + } + this._gcdSuccessCallback(data); + printLogs( + "onConversionDataSuccess: " + JSON.stringify(args) + ); } catch (e) { - printLogs(`registerConversionListener Error:${e}`); + printLogs(`onConversionDataSuccess Error: ${e}`); } - } - - if(args.onDeepLinking){ - try{ - appsFlyerLibInstance.subscribeForDeepLink(new com.appsflyer.deeplink.DeepLinkListener({ - _onDeepLinkingCallback: args.onDeepLinking, - onDeepLinking(deepLinkResult: Object): void { - printLogs(`DeepLinkResult: ${deepLinkResult.toString()}`); - this._onDeepLinkingCallback(deepLinkResult); + } else { + printLogs( + `onConversionDataSuccess: callback is not a function` + ); + } + }, + onConversionDataFail(error: string): void { + if (!this._gcdFailureCallback) { + return; + } + if (typeof this._gcdFailureCallback === "function") { + try { + this._gcdFailureCallback(error); + printLogs("onConversionDataFail error: " + error); + } catch (e) { + printLogs(`onConversionDataFail Error: ${e}`); + } + } else { + printLogs( + "onConversionDataFail: callback is not a function" + ); + } + }, + onAttributionFailure(error: string): void { + if (!this._oaoaFailureCallback) { + return; + } + if (typeof this._oaoaFailureCallback === "function") { + try { + this._oaoaFailureCallback(error); + printLogs("onAttributionFailure error: " + error); + } catch (e) { + printLogs(`onAttributionFailure Error: ${e}`); + } + } else { + printLogs( + "onAttributionFailure: callback is not a function" + ); + } + }, + onAppOpenAttribution( + onAppOpenAttributionData: java.util.Map + ): void { + if (!this._oaoaSuccessCallback) { + return; + } + if (typeof this._oaoaSuccessCallback === "function") { + try { + let data = {}; + for (const key of stringSetToStringArray( + onAppOpenAttributionData.keySet() + )) { + data[key] = onAppOpenAttributionData.get(key); } - })); - } catch(e){ - printLogs(`onDeepLinking Error: ${e}`); + + printLogs( + "onAppOpenAttribution: " + JSON.stringify(data) + ); + } catch (e) { + printLogs(`onAppOpenAttribution Error: ${e}`); + } + } else { + printLogs( + `onAppOpenAttribution: callback is not a function` + ); } - } - - const platform_extension = com.appsflyer.internal.platform_extension; - const pluginInfoClass = new platform_extension.PluginInfo(platform_extension.Plugin.NATIVE_SCRIPT, "6.12.1", new java.util.HashMap()); - appsFlyerLibInstance.setPluginInfo(pluginInfoClass); - - appsFlyerLibInstance.init(args.devKey,_appsFlyerConversionListener,(Application.android.context || (com).tns.NativeScriptApplication.getInstance())); - - _start(appsFlyerLibInstance); - - appsFlyerLibInstance.start((com).tns.NativeScriptApplication.getInstance()); - - resolve({status: "success"}); - } else { - reject({status: "failure", message: "com.appsflyer.AppsFlyerLib is not defined"}); - } - } catch (ex) { - printLogs("Error: " + ex); - reject(ex); + }, + }); + } catch (e) { + printLogs(`registerConversionListener Error:${e}`); + } } - }); -}; - -function _start (_instance: com.appsflyer.AppsFlyerLib) { - printLogs("start is called"); - - const c = Application.android.context || (com).tns.NativeScriptApplication.getInstance(); - _instance.logEvent(c, null, null); -} - -export const logEvent = function (args: LogEventOptions) { - return new Promise(function (resolve, reject) { - try { - if (args.onSuccess || args.onError) { - try { - _appsFlyerRequestListener = new com.appsflyer.attribution.AppsFlyerRequestListener({ - _successCallback: args.onSuccess, - _failureCallback: args.onError, - onSuccess(): void { - if (!this._successCallback) { - return; - } - if (typeof this._successCallback === 'function') { - try { - this._successCallback(args); - printLogs("logEvent success: " + JSON.stringify(args)); - } catch (e) { - printLogs(`onLogEventRequestSuccess Error: ${e}`); - } - } else { - printLogs(`onLogEventRequestSuccess: callback is not a function`); - } - resolve({status: args}); - }, - onError(error: string): void { - if (!this._failureCallback) { - return; - } - if (typeof this._failureCallback === 'function') { - try { - this._failureCallback(error); - printLogs("logEvent error: " + error); - } catch (e) { - printLogs(`onLogEventRequestFailure Error: ${e}`); - } - } else { - printLogs(`onLogRequestFailure: callback is not a function`); - } - resolve({status: "failure"}); - }, - }); - } catch (e) { - printLogs(`AppsFlyerRequestListener Error:${e}`); - - } - } - const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); - const c = Application.android.context || (com).tns.NativeScriptApplication.getInstance(); - appsFlyerLibInstance.logEvent(c, args.eventName, _toValue(args.eventValues), _appsFlyerRequestListener); - - - } catch (ex) { - printLogs("Error: " + ex); - reject(ex); + if (args.onDeepLinking) { + try { + appsFlyerLibInstance.subscribeForDeepLink( + new com.appsflyer.deeplink.DeepLinkListener({ + _onDeepLinkingCallback: args.onDeepLinking, + onDeepLinking(deepLinkResult: Object): void { + printLogs(`DeepLinkResult: ${deepLinkResult.toString()}`); + this._onDeepLinkingCallback(deepLinkResult); + }, + }) + ); + } catch (e) { + printLogs(`onDeepLinking Error: ${e}`); + } } - }); -}; -export const setCustomerUserId = function (userId: string) { - - return new Promise(function (resolve, reject) { - try { - const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); - appsFlyerLibInstance.setCustomerUserId(userId); - - resolve({status: "success"}); - } catch (ex) { - printLogs("setCustomerUserId Error: " + ex); - reject(ex); + const platform_extension = com.appsflyer.internal.platform_extension; + const pluginInfoClass = new platform_extension.PluginInfo( + platform_extension.Plugin.NATIVE_SCRIPT, + "6.13.0", + new java.util.HashMap() + ); + appsFlyerLibInstance.setPluginInfo(pluginInfoClass); + + appsFlyerLibInstance.init( + args.devKey, + _appsFlyerConversionListener, + Application.android.context || + (com).tns.NativeScriptApplication.getInstance() + ); + + const shouldManuallyStart = args.manualStart === true; + if (!shouldManuallyStart) { + startSdk(); } - }); -}; - -export const setAppInviteOneLink = function (link: string) { - - return new Promise(function (resolve, reject) { - try { - const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); - appsFlyerLibInstance.setAppInviteOneLink(link); - resolve({status: "success"}); - } catch (ex) { - printLogs("setAppInviteOneLink Error: " + ex); - reject(ex); - } - }); + resolve({ status: "success" }); + } else { + reject({ + status: "failure", + message: "com.appsflyer.AppsFlyerLib is not defined", + }); + } + } catch (ex) { + printLogs("Error: " + ex); + reject(ex); + } + }); }; -export const generateInviteUrl = function (args: AppsFlyerLinkGeneratorArgs) { +const startSdk = function () { + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + _start(appsFlyerLibInstance); + appsFlyerLibInstance.start( + (com).tns.NativeScriptApplication.getInstance() + ); +}; - return new Promise(function (resolve, reject) { - try { - const params = args.params; - const channel: String = params.channel; - const campaign: String = params.campaign; - const referrerName: String = params.referrerName; - const referrerImageUrl: String = params.referrerImageUrl; - const customerID: String = params.customerID; - const baseDeepLink: String = params.baseDeepLink; - const brandDomain: String = params.brandDomain; - - const appsflyerShareInviteHelper: com.appsflyer.share.ShareInviteHelper = com.appsflyer.share.ShareInviteHelper; - const linkGenerator: com.appsflyer.share.LinkGenerator = appsflyerShareInviteHelper.generateInviteUrl(Application.android.context); - - if (channel != null && channel != "") { - linkGenerator.setChannel(String(channel)); - } - if (campaign != null && campaign != "") { - linkGenerator.setCampaign(String(campaign)); - } - if (referrerName != null && referrerName != "") { - linkGenerator.setReferrerName(String(referrerName)); - } - if (referrerImageUrl != null && referrerImageUrl != "") { - linkGenerator.setReferrerImageURL(String(referrerImageUrl)); - } - if (customerID != null && customerID != "") { - linkGenerator.setReferrerCustomerId(String(customerID)); - } - if (baseDeepLink != null && baseDeepLink != "") { - linkGenerator.setBaseDeeplink(String(baseDeepLink)); - } - if (brandDomain != null && brandDomain != "") { - linkGenerator.setBrandDomain(String(brandDomain)); - } +function _start(_instance: com.appsflyer.AppsFlyerLib) { + printLogs("start is called"); - if (!isEmpty(params.userParams)) { - Object.entries(params.userParams).forEach(([key, value]) => { - linkGenerator.addParameter(key, String(value)); - }) - } + const c = + Application.android.context || + (com).tns.NativeScriptApplication.getInstance(); + _instance.logEvent(c, null, null); +} - if(args.onSuccess && args.onError){ - const listener: com.appsflyer.CreateOneLinkHttpTask.ResponseListener = new com.appsflyer.CreateOneLinkHttpTask.ResponseListener({ +const logEvent = function (args: LogEventOptions) { + return new Promise(function (resolve, reject) { + try { + if (args.onSuccess || args.onError) { + try { + _appsFlyerRequestListener = + new com.appsflyer.attribution.AppsFlyerRequestListener({ _successCallback: args.onSuccess, _failureCallback: args.onError, - onResponse(): void { + onSuccess(): void { if (!this._successCallback) { return; } - if (typeof this._successCallback === 'function') { + if (typeof this._successCallback === "function") { try { this._successCallback(args); - printLogs("generateInviteUrl success: " + JSON.stringify(args)); + printLogs("logEvent success: " + JSON.stringify(args)); } catch (e) { - printLogs(`generateInviteUrl Error: ${e}`); + printLogs(`onLogEventRequestSuccess Error: ${e}`); } } else { - printLogs(`generateInviteUrl: callback is not a function`); + printLogs( + `onLogEventRequestSuccess: callback is not a function` + ); } - resolve({status: args}); + resolve({ status: args }); }, - onResponseError(error: string): void { + onError(error: string): void { if (!this._failureCallback) { return; } - if (typeof this._failureCallback === 'function') { + if (typeof this._failureCallback === "function") { try { this._failureCallback(error); - printLogs("generateInviteUrl error: " + error); + printLogs("logEvent error: " + error); } catch (e) { - printLogs(`generateInviteUrl Error: ${e}`); + printLogs(`onLogEventRequestFailure Error: ${e}`); } } else { - printLogs(`generateInviteUrl: callback is not a function`); + printLogs(`onLogRequestFailure: callback is not a function`); } - resolve({status: "failure"}); + resolve({ status: "failure" }); }, }); + } catch (e) { + printLogs(`AppsFlyerRequestListener Error:${e}`); + } + } + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + const c = + Application.android.context || + (com).tns.NativeScriptApplication.getInstance(); + appsFlyerLibInstance.logEvent( + c, + args.eventName, + _toValue(args.eventValues), + _appsFlyerRequestListener + ); + } catch (ex) { + printLogs("Error: " + ex); + reject(ex); + } + }); +}; - linkGenerator.generateLink(Application.android.context, listener); - } - +const getAppsFlyerUID = function () { + try { + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + const uid: string = appsFlyerLibInstance.getAppsFlyerUID( + Utils.android.getApplicationContext() + ); + return uid; + } catch (error) { + throw new Error("Failed to get AppsFlyer UID: " + error.message); + } +}; - resolve({status: "success"}); - } catch (ex) { - printLogs("generateInviteUrl Error: " + ex); - reject(ex); - } - }); +const setCustomerUserId = function (userId: string) { + return new Promise(function (resolve, reject) { + try { + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + appsFlyerLibInstance.setCustomerUserId(userId); + + resolve({ status: "success" }); + } catch (ex) { + printLogs("setCustomerUserId Error: " + ex); + reject(ex); + } + }); +}; + +const enableTCFDataCollection = function (shouldCollect: boolean) { + return new Promise(function (resolve, reject) { + try { + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + appsFlyerLibInstance.enableTCFDataCollection(shouldCollect); + + resolve({ status: "success" }); + } catch (ex) { + printLogs("enableTCFDataCollection Error: " + ex); + reject(ex); + } + }); +}; + +const setConsentData = function (consent) { + return new Promise((resolve, reject) => { + try { + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + let consentData; + + if (consent.isUserSubjectToGDPR) { + // Provide default values for booleans if not defined + const hasConsentForDataUsage = consent.hasConsentForDataUsage === true; + const hasConsentForAdsPersonalization = consent.hasConsentForAdsPersonalization === true; + + consentData = com.appsflyer.AppsFlyerConsent.forGDPRUser( + hasConsentForDataUsage, + hasConsentForAdsPersonalization + ); + } else { + consentData = com.appsflyer.AppsFlyerConsent.forNonGDPRUser(); + } + + appsFlyerLibInstance.setConsentData(consentData); + + resolve({ status: "success" }); + } catch (ex) { + console.error(`Error setting consent data: ${ex.message}`); + reject(new Error(`Error setting consent data: ${ex.message}`)); + } + }); +}; + +const setAppInviteOneLink = function (link: string) { + return new Promise(function (resolve, reject) { + try { + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + appsFlyerLibInstance.setAppInviteOneLink(link); + + resolve({ status: "success" }); + } catch (ex) { + printLogs("setAppInviteOneLink Error: " + ex); + reject(ex); + } + }); +}; + +const generateInviteUrl = function (args: AppsFlyerLinkGeneratorArgs) { + return new Promise(function (resolve, reject) { + try { + const params = args.params; + const channel: String = params.channel; + const campaign: String = params.campaign; + const referrerName: String = params.referrerName; + const referrerImageUrl: String = params.referrerImageUrl; + const customerID: String = params.customerID; + const baseDeepLink: String = params.baseDeepLink; + const brandDomain: String = params.brandDomain; + + const appsflyerShareInviteHelper: com.appsflyer.share.ShareInviteHelper = + com.appsflyer.share.ShareInviteHelper; + const linkGenerator: com.appsflyer.share.LinkGenerator = + appsflyerShareInviteHelper.generateInviteUrl( + Application.android.context + ); + + if (channel != null && channel != "") { + linkGenerator.setChannel(String(channel)); + } + if (campaign != null && campaign != "") { + linkGenerator.setCampaign(String(campaign)); + } + if (referrerName != null && referrerName != "") { + linkGenerator.setReferrerName(String(referrerName)); + } + if (referrerImageUrl != null && referrerImageUrl != "") { + linkGenerator.setReferrerImageURL(String(referrerImageUrl)); + } + if (customerID != null && customerID != "") { + linkGenerator.setReferrerCustomerId(String(customerID)); + } + if (baseDeepLink != null && baseDeepLink != "") { + linkGenerator.setBaseDeeplink(String(baseDeepLink)); + } + if (brandDomain != null && brandDomain != "") { + linkGenerator.setBrandDomain(String(brandDomain)); + } + + if (!isEmpty(params.userParams)) { + Object.entries(params.userParams).forEach(([key, value]) => { + linkGenerator.addParameter(key, String(value)); + }); + } + + if (args.onSuccess && args.onError) { + const listener: com.appsflyer.CreateOneLinkHttpTask.ResponseListener = + new com.appsflyer.CreateOneLinkHttpTask.ResponseListener({ + _successCallback: args.onSuccess, + _failureCallback: args.onError, + onResponse(): void { + if (!this._successCallback) { + return; + } + if (typeof this._successCallback === "function") { + try { + this._successCallback(args); + printLogs( + "generateInviteUrl success: " + JSON.stringify(args) + ); + } catch (e) { + printLogs(`generateInviteUrl Error: ${e}`); + } + } else { + printLogs(`generateInviteUrl: callback is not a function`); + } + resolve({ status: args }); + }, + onResponseError(error: string): void { + if (!this._failureCallback) { + return; + } + if (typeof this._failureCallback === "function") { + try { + this._failureCallback(error); + printLogs("generateInviteUrl error: " + error); + } catch (e) { + printLogs(`generateInviteUrl Error: ${e}`); + } + } else { + printLogs(`generateInviteUrl: callback is not a function`); + } + resolve({ status: "failure" }); + }, + }); + + linkGenerator.generateLink(Application.android.context, listener); + } + + resolve({ status: "success" }); + } catch (ex) { + printLogs("generateInviteUrl Error: " + ex); + reject(ex); + } + }); }; function isEmpty(obj) { for (const prop in obj) { @@ -339,108 +444,131 @@ function isEmpty(obj) { return true; } -export const stop = function (isStopped: bool) { - - return new Promise(function (resolve, reject) { - try { - const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); - appsFlyerLibInstance.stop(isStopped, Application.android.context); - - resolve({status: "success"}); - } catch (ex) { - printLogs("stop Error: " + ex); - reject(ex); - } - }); +const stop = function (isStopped: bool) { + return new Promise(function (resolve, reject) { + try { + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + appsFlyerLibInstance.stop(isStopped, Application.android.context); + + resolve({ status: "success" }); + } catch (ex) { + printLogs("stop Error: " + ex); + reject(ex); + } + }); }; -export const setSharingFilter = function (partners: Array) { - +const setSharingFilter = function (partners: Array) { return new Promise(function (resolve, reject) { - try { - const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); - appsFlyerLibInstance.setSharingFilter(partners); - - resolve({status: "success"}); - } catch (ex) { - printLogs("setSharingFilter Error: " + ex); - reject(ex); - } + try { + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + appsFlyerLibInstance.setSharingFilter(partners); + + resolve({ status: "success" }); + } catch (ex) { + printLogs("setSharingFilter Error: " + ex); + reject(ex); + } }); }; -export const setSharingFilterForAllPartners = function () { - +const setSharingFilterForAllPartners = function () { return new Promise(function (resolve, reject) { - try { - const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); - appsFlyerLibInstance.setSharingFilterForAllPartners(); - - resolve({status: "success"}); - } catch (ex) { - printLogs("setSharingFilterForAllPartners Error: " + ex); - reject(ex); - } + try { + const appsFlyerLibInstance = com.appsflyer.AppsFlyerLib.getInstance(); + appsFlyerLibInstance.setSharingFilterForAllPartners(); + + resolve({ status: "success" }); + } catch (ex) { + printLogs("setSharingFilterForAllPartners Error: " + ex); + reject(ex); + } }); }; -export const _toHashMap = function(obj: Object) { - const node = new java.util.HashMap(); - for (const property in obj) { - if (obj.hasOwnProperty(property)) { - if (obj[property] !== null) { - switch (typeof obj[property]) { - case 'object': - // note: since this function has no second argument, - // it appears the "node" being passed in this recursive call is unused - // TypeScript detected this, so commenting out for now - node.put(property, _toHashMap(obj[property]/*, node*/)); - break; - case 'boolean': - node.put(property, java.lang.Boolean.valueOf(String(obj[property]))); - break; - case 'number': - if (Number(obj[property]) === obj[property] && obj[property] % 1 === 0) { - node.put(property, java.lang.Long.valueOf(String(obj[property]))); - } else { - node.put(property, java.lang.Double.valueOf(String(obj[property]))); - } - break; - case 'string': - node.put(property, String(obj[property])); - break; - } +const _toHashMap = function (obj: Object) { + const node = new java.util.HashMap(); + for (const property in obj) { + if (obj.hasOwnProperty(property)) { + if (obj[property] !== null) { + switch (typeof obj[property]) { + case "object": + // note: since this function has no second argument, + // it appears the "node" being passed in this recursive call is unused + // TypeScript detected this, so commenting out for now + node.put(property, _toHashMap(obj[property] /*, node*/)); + break; + case "boolean": + node.put( + property, + java.lang.Boolean.valueOf(String(obj[property])) + ); + break; + case "number": + if ( + Number(obj[property]) === obj[property] && + obj[property] % 1 === 0 + ) { + node.put(property, java.lang.Long.valueOf(String(obj[property]))); + } else { + node.put( + property, + java.lang.Double.valueOf(String(obj[property])) + ); } + break; + case "string": + node.put(property, String(obj[property])); + break; } + } } - return node; + } + return node; }; -export const _toValue = function(val: any){ - let returnVal = null; - if (val !== null) { - switch (typeof val) { - case 'object': - returnVal = _toHashMap(val); - break; - case 'boolean': - returnVal = java.lang.Boolean.valueOf(String(val)); - break; - case 'number': - if (Number(val) === val && val % 1 === 0) { - returnVal = java.lang.Long.valueOf(String(val)); - } else { - returnVal = java.lang.Double.valueOf(String(val)); - } - break; - case 'string': - returnVal = String(val); - break; +const _toValue = function (val: any) { + let returnVal = null; + if (val !== null) { + switch (typeof val) { + case "object": + returnVal = _toHashMap(val); + break; + case "boolean": + returnVal = java.lang.Boolean.valueOf(String(val)); + break; + case "number": + if (Number(val) === val && val % 1 === 0) { + returnVal = java.lang.Long.valueOf(String(val)); + } else { + returnVal = java.lang.Double.valueOf(String(val)); } + break; + case "string": + returnVal = String(val); + break; } - return returnVal; + } + return returnVal; }; -function printLogs(logs){ - if (_isDebugLocal) { - console.log("AppsFlyer :: " + logs); - } -} \ No newline at end of file +function printLogs(logs) { + if (_isDebugLocal) { + console.log("AppsFlyer :: " + logs); + } +} + +export { + initSdk, + startSdk, + logEvent, + stop, + setCustomerUserId, + setAppInviteOneLink, + generateInviteUrl, + getAppsFlyerUID, + enableTCFDataCollection, + setConsentData, + setSharingFilter, + setSharingFilterForAllPartners, + _toHashMap, + _toValue, +}; diff --git a/appsflyer.ios.d.ts b/appsflyer.ios.d.ts index 43ae253b..7df11223 100644 --- a/appsflyer.ios.d.ts +++ b/appsflyer.ios.d.ts @@ -1,8 +1,12 @@ -import { InitSDKOptions, LogEventOptions } from './index'; +import { InitSDKOptions, LogEventOptions , AppsFlyerLinkGeneratorArgs, AppsFlyerConsentArgs} from './index'; declare const initSdk: (args: InitSDKOptions) => Promise; +declare const startSdk: () => void; declare const logEvent: (args: LogEventOptions) => Promise; -declare const stop: (isStopped: bool) => Promise; +declare const stop: (isStopped: boolean) => Promise; +declare const setConsentData: (consent: AppsFlyerConsentArgs) => Promise; +declare const enableTCFDataCollection: (shouldCollect: boolean) => Promise; declare const setCustomerUserId: (userId: string) => Promise; declare const setAppInviteOneLink: (link: string) => Promise; +declare const getAppsFlyerUID: () => string; declare const generateInviteUrl: (args: AppsFlyerLinkGeneratorArgs) => Promise; -export { initSdk, logEvent, stop, setCustomerUserId, setAppInviteOneLink, generateInviteUrl, }; +export { initSdk, startSdk, logEvent, stop, setCustomerUserId, setAppInviteOneLink, generateInviteUrl, getAppsFlyerUID, enableTCFDataCollection, setConsentData, }; diff --git a/appsflyer.ios.ts b/appsflyer.ios.ts index 2b61b3d6..8b44078d 100644 --- a/appsflyer.ios.ts +++ b/appsflyer.ios.ts @@ -1,12 +1,7 @@ // @ts-nocheck -import { - Utils -} from '@nativescript/core'; +import { Utils } from "@nativescript/core"; -import { - InitSDKOptions, - LogEventOptions, -} from './index'; +import { AppsFlyerConsentArgs, InitSDKOptions, LogEventOptions } from "./index"; const nsArrayToJSArray = Utils.ios.collections.nsArrayToJSArray; @@ -15,217 +10,288 @@ let _isDebugLocal = false; let _conversionDataDelegate; let _deepLinkDelegate; -const initSdk = function (args: InitSDKOptions) { - - return new Promise(function (resolve, reject) { - try { - if (typeof(AppsFlyerLib) !== "undefined") { - - AppsFlyerLib.shared().appleAppID = args.appId; - AppsFlyerLib.shared().appsFlyerDevKey = args.devKey; - AppsFlyerLib.shared().isDebug = args.isDebug === true; - - if(args.timeToWaitForATTUserAuthorization){ - AppsFlyerLib.shared().waitForATTUserAuthorizationWithTimeoutInterval(args.timeToWaitForATTUserAuthorization); - } - - _isDebugLocal = AppsFlyerLib.shared().isDebug; - - if (_isDebugLocal) { - console.log("AF-I :: appsFlyer.initSdk: " + JSON.stringify(args)); - } - - if (args.onConversionDataSuccess || args.onConversionDataFail) { - try { - _conversionDataDelegate = ConversionDataDelegate.initWithCallbacks( - args.onConversionDataSuccess, - args.onConversionDataFail, - args.onAppOpenAttribution, - args.onAppOpenAttributionFailure, - ); - AppsFlyerLib.shared().delegate = _conversionDataDelegate; - } catch (e) { - console.error(`AF-I :: delegate assignment Error: ${e}`); - } - } - if(args.onDeepLinking){ - try{ - _deepLinkDelegate = DeepLinkDelegate.DeepLinkCallback( - args.onDeepLinking - ); - AppsFlyerLib.shared().deepLinkDelegate = _deepLinkDelegate; - }catch (e){ - console.error(`AF-I :: onDeepLinking Error: ${e}`); - } - } - - AppsFlyerLib.shared().setPluginInfoWithPluginVersionAdditionalParams(AFSDKPlugin.AFSDKPluginNativeScript, "6.12.1", null); - - AppsFlyerLib.shared().start(); - - resolve({status: "success"}); - } else { - reject({status: "failure", message: "AppsFlyer is not defined"}); - } - } catch (ex) { - console.log("AF_IOS :: Error: " + ex); - reject(ex); - } - }); +const startSdk = function () { + if (typeof AppsFlyerLib !== "undefined") { + console.log("AF-I :: Starting AppsFlyer SDK"); + AppsFlyerLib.shared().start(); + } else { + console.error("AF-I :: AppsFlyerLib is not defined, failed to start the SDK."); + } }; +const initSdk = function (args: InitSDKOptions) { + return new Promise(function (resolve, reject) { + try { + if (typeof AppsFlyerLib !== "undefined") { + AppsFlyerLib.shared().appleAppID = args.appId; + AppsFlyerLib.shared().appsFlyerDevKey = args.devKey; + AppsFlyerLib.shared().isDebug = args.isDebug === true; + + if (args.timeToWaitForATTUserAuthorization) { + AppsFlyerLib.shared().waitForATTUserAuthorizationWithTimeoutInterval( + args.timeToWaitForATTUserAuthorization + ); + } -const logEvent = function (args: LogEventOptions) { - - return new Promise(function (resolve, reject) { - try { - - if (typeof(AppsFlyerLib) !== "undefined") { - - if (_isDebugLocal) { - console.log("AF-I :: appsFlyer.logEvent: " + JSON.stringify(args)); - } + _isDebugLocal = AppsFlyerLib.shared().isDebug; - AppsFlyerLib.shared().logEventWithValues(args.eventName, args.eventValues); + if (_isDebugLocal) { + console.log("AF-I :: appsFlyer.initSdk: " + JSON.stringify(args)); + } - resolve({status: "success"}); - } else { - reject({status: "failure", message: "AppsFlyer is not defined, call 1st 'initSdk'"}); - } + if (args.onConversionDataSuccess || args.onConversionDataFail) { + try { + _conversionDataDelegate = ConversionDataDelegate.initWithCallbacks( + args.onConversionDataSuccess, + args.onConversionDataFail, + args.onAppOpenAttribution, + args.onAppOpenAttributionFailure + ); + AppsFlyerLib.shared().delegate = _conversionDataDelegate; + } catch (e) { + console.error(`AF-I :: delegate assignment Error: ${e}`); + } + } + if (args.onDeepLinking) { + try { + _deepLinkDelegate = DeepLinkDelegate.DeepLinkCallback( + args.onDeepLinking + ); + AppsFlyerLib.shared().deepLinkDelegate = _deepLinkDelegate; + } catch (e) { + console.error(`AF-I :: onDeepLinking Error: ${e}`); + } + } - } catch (ex) { - console.log("AF_IOS :: Error: " + ex); - reject(ex); + AppsFlyerLib.shared().setPluginInfoWithPluginVersionAdditionalParams( + AFSDKPlugin.AFSDKPluginNativeScript, + "6.13.0", + null + ); + + const shouldManuallyStart = args.manualStart === true; + if (!shouldManuallyStart) { + startSdk(); } - }); + resolve({ status: "success" }); + } else { + reject({ status: "failure", message: "AppsFlyer is not defined" }); + } + } catch (ex) { + console.log("AF_IOS :: Error: " + ex); + reject(ex); + } + }); }; -const stop = function (isStopped: bool) { - - return new Promise(function (resolve, reject) { - try { - - if (typeof(AppsFlyerLib) !== "undefined") { +const logEvent = function (args: LogEventOptions) { + return new Promise(function (resolve, reject) { + try { + if (typeof AppsFlyerLib !== "undefined") { + if (_isDebugLocal) { + console.log("AF-I :: appsFlyer.logEvent: " + JSON.stringify(args)); + } - AppsFlyerLib.shared().isStopped = isStopped; + AppsFlyerLib.shared().logEventWithValues( + args.eventName, + args.eventValues + ); - resolve({status: "success"}); - } else { - reject({status: "failure", message: "AppsFlyer is not defined, call 1st 'initSdk'"}); - } + resolve({ status: "success" }); + } else { + reject({ + status: "failure", + message: "AppsFlyer is not defined, call 1st 'initSdk'", + }); + } + } catch (ex) { + console.log("AF_IOS :: Error: " + ex); + reject(ex); + } + }); +}; - } catch (ex) { - console.log("AF_IOS :: Error: " + ex); - reject(ex); - } - }); +const getAppsFlyerUID = function () { + if (typeof AppsFlyerLib !== "undefined") { + return AppsFlyerLib.shared().getAppsFlyerUID(); + } else { + throw new Error("AppsFlyer is not defined, call 'initSdk' first."); + } }; -const setCustomerUserId = function (userId: string) { +const enableTCFDataCollection = function (shouldCollect: bool) { + return new Promise(function (resolve, reject) { + try { + if (typeof AppsFlyerLib !== "undefined") { + AppsFlyerLib.shared().enableTCFDataCollection(shouldCollect); - return new Promise(function (resolve, reject) { - try { + resolve({ status: "success" }); + } else { + reject({ + status: "failure", + message: "AppsFlyer is not defined, call 1st 'initSdk'", + }); + } + } catch (ex) { + console.log("AF_IOS :: Error: " + ex); + reject(ex); + } + }); +}; - if (typeof(AppsFlyerLib) !== "undefined") { +const stop = function (isStopped: bool) { + return new Promise(function (resolve, reject) { + try { + if (typeof AppsFlyerLib !== "undefined") { + AppsFlyerLib.shared().isStopped = isStopped; - AppsFlyerLib.shared().customerUserID = userId; + resolve({ status: "success" }); + } else { + reject({ + status: "failure", + message: "AppsFlyer is not defined, call 1st 'initSdk'", + }); + } + } catch (ex) { + console.log("AF_IOS :: Error: " + ex); + reject(ex); + } + }); +}; - resolve({status: "success"}); - } else { - reject({status: "failure", message: "AppsFlyer is not defined, call 1st 'initSdk'"}); - } +const setCustomerUserId = function (userId: string) { + return new Promise(function (resolve, reject) { + try { + if (typeof AppsFlyerLib !== "undefined") { + AppsFlyerLib.shared().customerUserID = userId; - } catch (ex) { - console.log("AF_IOS :: Error: " + ex); - reject(ex); - } - }); + resolve({ status: "success" }); + } else { + reject({ + status: "failure", + message: "AppsFlyer is not defined, call 1st 'initSdk'", + }); + } + } catch (ex) { + console.log("AF_IOS :: Error: " + ex); + reject(ex); + } + }); }; const setAppInviteOneLink = function (link: string) { + return new Promise(function (resolve, reject) { + try { + if (typeof AppsFlyerLib !== "undefined") { + AppsFlyerLib.shared().appInviteOneLinkID = link; - return new Promise(function (resolve, reject) { - try { - - if (typeof(AppsFlyerLib) !== "undefined") { - - AppsFlyerLib.shared().appInviteOneLinkID = link; - - resolve({status: "success"}); - } else { - reject({status: "failure", message: "AppsFlyer is not defined, call 1st 'initSdk'"}); - } + resolve({ status: "success" }); + } else { + reject({ + status: "failure", + message: "AppsFlyer is not defined, call 1st 'initSdk'", + }); + } + } catch (ex) { + console.log("AF_IOS :: Error: " + ex); + reject(ex); + } + }); +}; - } catch (ex) { - console.log("AF_IOS :: Error: " + ex); - reject(ex); - } - }); +const setConsentData = function (consent) { + return new Promise((resolve, reject) => { + try { + if (typeof AppsFlyerLib === "undefined") { + throw new Error("AppsFlyerLib is not defined"); + } + let consentData; + // Check if isUserSubjectToGDPR is explicitly true + if (consent.isUserSubjectToGDPR === true) { + // Provide default values for booleans if not defined + const hasConsentForDataUsage = consent.hasConsentForDataUsage === true; + const hasConsentForAdsPersonalization = consent.hasConsentForAdsPersonalization === true; + consentData = AppsFlyerConsent.alloc().initForGDPRUserWithHasConsentForDataUsageHasConsentForAdsPersonalization( + hasConsentForDataUsage, + hasConsentForAdsPersonalization + ); + } else { + consentData = AppsFlyerConsent.alloc().initNonGDPRUser(); + } + AppsFlyerLib.shared().setConsentData(consentData); + resolve({ status: "success" }); + } catch (ex) { + reject(new Error(`Error setting consent data: ${ex.message}`)); + } + }); }; const generateInviteUrl = function (args: AppsFlyerLinkGeneratorArgs) { - - return new Promise(function (resolve, reject) { - try { - const params = args.params; - const channel: String = params.channel; - const campaign: String = params.campaign; - const referrerName: String = params.referrerName; - const referrerImageUrl: String = params.referrerImageUrl; - const customerID: String = params.customerID; - const baseDeepLink: String = params.baseDeepLink; - const brandDomain: String = params.brandDomain; - - const linkGenerator: function = function(linkGenerator: AppsFlyerLinkGenerator){ - if (channel != null && channel != "") { - linkGenerator.setChannel(String(channel)); - } - if (campaign != null && campaign != "") { - linkGenerator.setCampaign(String(campaign)); - } - if (referrerName != null && referrerName != "") { - linkGenerator.setReferrerName(String(referrerName)); - } - if (referrerImageUrl != null && referrerImageUrl != "") { - linkGenerator.setReferrerImageURL(String(referrerImageUrl)); - } - if (customerID != null && customerID != "") { - linkGenerator.setReferrerCustomerId(String(customerID)); - } - if (baseDeepLink != null && baseDeepLink != "") { - linkGenerator.setBaseDeeplink(String(baseDeepLink)); - } - if (brandDomain != null && brandDomain != "") { - linkGenerator.brandDomain = brandDomain - } - - if (!isEmpty(params.userParams)) { - Object.entries(params.userParams).forEach(([key, value]) => { - linkGenerator.addParameterValueForKey(String(value), key); - }) - } - return linkGenerator + return new Promise(function (resolve, reject) { + try { + const params = args.params; + const channel: String = params.channel; + const campaign: String = params.campaign; + const referrerName: String = params.referrerName; + const referrerImageUrl: String = params.referrerImageUrl; + const customerID: String = params.customerID; + const baseDeepLink: String = params.baseDeepLink; + const brandDomain: String = params.brandDomain; + + const linkGenerator: function = function ( + linkGenerator: AppsFlyerLinkGenerator + ) { + if (channel != null && channel != "") { + linkGenerator.setChannel(String(channel)); } - - let completionHandler = function(url: string){}; - if(args.onSuccess && args.onError){ - completionHandler = function(url: string){ - if(url !== null){ - args.onSuccess(url); - }else{ - args.onError("failed to generate link"); - } - } + if (campaign != null && campaign != "") { + linkGenerator.setCampaign(String(campaign)); + } + if (referrerName != null && referrerName != "") { + linkGenerator.setReferrerName(String(referrerName)); + } + if (referrerImageUrl != null && referrerImageUrl != "") { + linkGenerator.setReferrerImageURL(String(referrerImageUrl)); + } + if (customerID != null && customerID != "") { + linkGenerator.setReferrerCustomerId(String(customerID)); + } + if (baseDeepLink != null && baseDeepLink != "") { + linkGenerator.setBaseDeeplink(String(baseDeepLink)); + } + if (brandDomain != null && brandDomain != "") { + linkGenerator.brandDomain = brandDomain; } - - AppsFlyerShareInviteHelper.generateInviteUrlWithLinkGeneratorCompletionHandler(linkGenerator, completionHandler) - } catch (ex) { - console.log("AF_IOS :: Error: " + ex); - reject(ex); + if (!isEmpty(params.userParams)) { + Object.entries(params.userParams).forEach(([key, value]) => { + linkGenerator.addParameterValueForKey(String(value), key); + }); + } + return linkGenerator; + }; + + let completionHandler = function (url: string) {}; + if (args.onSuccess && args.onError) { + completionHandler = function (url: string) { + if (url !== null) { + args.onSuccess(url); + } else { + args.onError("failed to generate link"); + } + }; } - }); + + AppsFlyerShareInviteHelper.generateInviteUrlWithLinkGeneratorCompletionHandler( + linkGenerator, + completionHandler + ); + } catch (ex) { + console.log("AF_IOS :: Error: " + ex); + reject(ex); + } + }); }; function isEmpty(obj) { @@ -240,151 +306,169 @@ function isEmpty(obj) { @NativeClass class DeepLinkDelegate extends NSObject implements AppsFlyerDeepLinkDelegate { - public static ObjCProtocols = [AppsFlyerDeepLinkDelegate]; + public static ObjCProtocols = [AppsFlyerDeepLinkDelegate]; - private _didResolveDeepLink: (obj: Object) => void; + private _didResolveDeepLink: (obj: Object) => void; - public static DeepLinkCallback( - didResolveDeepLink: (obj: Object) => void - ): DeepLinkDelegate { - const delegate: DeepLinkDelegate = DeepLinkDelegate.new() as DeepLinkDelegate; - delegate._didResolveDeepLink = didResolveDeepLink; - return delegate; - } + public static DeepLinkCallback( + didResolveDeepLink: (obj: Object) => void + ): DeepLinkDelegate { + const delegate: DeepLinkDelegate = + DeepLinkDelegate.new() as DeepLinkDelegate; + delegate._didResolveDeepLink = didResolveDeepLink; + return delegate; + } - public didResolveDeepLink(DeepLinkResult: AppsFlyerDeepLinkResult): void { - if (!this._didResolveDeepLink) { - return; - } - if (typeof this._didResolveDeepLink === 'function') { - if (DeepLinkResult) { - this._didResolveDeepLink(DeepLinkResult.deepLink); - } - } else { - console.error(`AF-I :: _didResolveDeepLink: callback is not a function`); + public didResolveDeepLink(DeepLinkResult: AppsFlyerDeepLinkResult): void { + if (!this._didResolveDeepLink) { + return; + } + if (typeof this._didResolveDeepLink === "function") { + if (DeepLinkResult) { + this._didResolveDeepLink(DeepLinkResult.deepLink); } + } else { + console.error(`AF-I :: _didResolveDeepLink: callback is not a function`); } - + } } @NativeClass class ConversionDataDelegate extends NSObject implements AppsFlyerLibDelegate { - public static ObjCProtocols = [AppsFlyerLibDelegate]; - - private _gcdSuccessCallback: (obj: Object) => void; - private _gcdFailureCallback: (err: string) => void; - private _oaoaSuccessCallback: (obj: Object) => void; - private _oaoaFailureCallback: (err: string) => void; - - public static initWithCallbacks( - gcdSuccessCallback: (obj: Object) => void, - gcdFailureCallback: (err: string) => void, - oaoaSuccessCallback: (obj: Object) => void, - oaoaFailureCallback: (err: string) => void - ): ConversionDataDelegate { - const delegate: ConversionDataDelegate = ConversionDataDelegate.new() as ConversionDataDelegate; - delegate._gcdSuccessCallback = gcdSuccessCallback; - delegate._gcdFailureCallback = gcdFailureCallback; - delegate._oaoaSuccessCallback = oaoaSuccessCallback; - delegate._oaoaFailureCallback = oaoaFailureCallback; - return delegate; - } + public static ObjCProtocols = [AppsFlyerLibDelegate]; + + private _gcdSuccessCallback: (obj: Object) => void; + private _gcdFailureCallback: (err: string) => void; + private _oaoaSuccessCallback: (obj: Object) => void; + private _oaoaFailureCallback: (err: string) => void; + + public static initWithCallbacks( + gcdSuccessCallback: (obj: Object) => void, + gcdFailureCallback: (err: string) => void, + oaoaSuccessCallback: (obj: Object) => void, + oaoaFailureCallback: (err: string) => void + ): ConversionDataDelegate { + const delegate: ConversionDataDelegate = + ConversionDataDelegate.new() as ConversionDataDelegate; + delegate._gcdSuccessCallback = gcdSuccessCallback; + delegate._gcdFailureCallback = gcdFailureCallback; + delegate._oaoaSuccessCallback = oaoaSuccessCallback; + delegate._oaoaFailureCallback = oaoaFailureCallback; + return delegate; + } - public onConversionDataSuccess(installData: NSDictionary): void { - if (!this._gcdSuccessCallback) { - return; - } - if (typeof this._gcdSuccessCallback === 'function') { - const data = {}; - if (installData && installData.allKeys) { - let keys; - try { - keys = nsArrayToJSArray(installData.allKeys); - } catch (e) { - console.error(`AF-I :: onConversionDataReceived allKeys Error: ${e}`); - } - if (keys && keys.length) { - for (const key of keys) { - try { - data[key] = installData.objectForKey(key); - } catch (e) { - console.error(`AF-I :: onConversionDataReceived objectForKey Error: ${e}`); - } + public onConversionDataSuccess( + installData: NSDictionary + ): void { + if (!this._gcdSuccessCallback) { + return; + } + if (typeof this._gcdSuccessCallback === "function") { + const data = {}; + if (installData && installData.allKeys) { + let keys; + try { + keys = nsArrayToJSArray(installData.allKeys); + } catch (e) { + console.error(`AF-I :: onConversionDataReceived allKeys Error: ${e}`); + } + if (keys && keys.length) { + for (const key of keys) { + try { + data[key] = installData.objectForKey(key); + } catch (e) { + console.error( + `AF-I :: onConversionDataReceived objectForKey Error: ${e}` + ); } } } - this._gcdSuccessCallback(data); - } else { - console.error(`AF-I :: onConversionDataReceived: callback is not a function`); } + this._gcdSuccessCallback(data); + } else { + console.error( + `AF-I :: onConversionDataReceived: callback is not a function` + ); } + } - public onConversionDataFail(error: NSError): void { - if (!this._gcdFailureCallback) { - return; + public onConversionDataFail(error: NSError): void { + if (!this._gcdFailureCallback) { + return; + } + if (typeof this._gcdFailureCallback === "function") { + try { + this._gcdFailureCallback(`${error}`); + } catch (e) { + console.error(`AF-I :: onConversionDataRequestFailure Error: ${e}`); } - if (typeof this._gcdFailureCallback === 'function') { + } else { + console.error( + `AF-I :: onConversionDataRequestFailure: callback is not a function` + ); + } + } + + onAppOpenAttribution?(attributionData: NSDictionary): void { + if (!this._oaoaSuccessCallback) { + return; + } + if (typeof this._oaoaSuccessCallback === "function") { + const data = {}; + if (attributionData && attributionData.allKeys) { + let keys; try { - this._gcdFailureCallback(`${error}`); + keys = nsArrayToJSArray(attributionData.allKeys); } catch (e) { - console.error(`AF-I :: onConversionDataRequestFailure Error: ${e}`); + console.error(`AF-I :: onConversionDataReceived allKeys Error: ${e}`); } - } else { - console.error(`AF-I :: onConversionDataRequestFailure: callback is not a function`); - } - } - - onAppOpenAttribution?(attributionData: NSDictionary): void{ - if (!this._oaoaSuccessCallback) { - return; - } - if (typeof this._oaoaSuccessCallback === 'function') { - const data = {}; - if (attributionData && attributionData.allKeys) { - let keys; - try { - keys = nsArrayToJSArray(attributionData.allKeys); - } catch (e) { - console.error(`AF-I :: onConversionDataReceived allKeys Error: ${e}`); - } - if (keys && keys.length) { - for (const key of keys) { - try { - data[key] = attributionData.objectForKey(key); - } catch (e) { - console.error(`AF-I :: onConversionDataReceived objectForKey Error: ${e}`); - } + if (keys && keys.length) { + for (const key of keys) { + try { + data[key] = attributionData.objectForKey(key); + } catch (e) { + console.error( + `AF-I :: onConversionDataReceived objectForKey Error: ${e}` + ); } } } - this._oaoaSuccessCallback(data); - } else { - console.error(`AF-I :: onConversionDataReceived: callback is not a function`); } + this._oaoaSuccessCallback(data); + } else { + console.error( + `AF-I :: onConversionDataReceived: callback is not a function` + ); } + } - onAppOpenAttributionFailure?(error: NSError): void{ - if (!this._oaoaFailureCallback) { - return; - } - if (typeof this._oaoaFailureCallback === 'function') { - try { - this._oaoaFailureCallback(`${error}`); - } catch (e) { - console.error(`AF-I :: onConversionDataRequestFailure Error: ${e}`); - } - } else { - console.error(`AF-I :: onConversionDataRequestFailure: callback is not a function`); + onAppOpenAttributionFailure?(error: NSError): void { + if (!this._oaoaFailureCallback) { + return; + } + if (typeof this._oaoaFailureCallback === "function") { + try { + this._oaoaFailureCallback(`${error}`); + } catch (e) { + console.error(`AF-I :: onConversionDataRequestFailure Error: ${e}`); } + } else { + console.error( + `AF-I :: onConversionDataRequestFailure: callback is not a function` + ); } - + } } export { initSdk, + startSdk, logEvent, stop, setCustomerUserId, setAppInviteOneLink, generateInviteUrl, -} \ No newline at end of file + getAppsFlyerUID, + enableTCFDataCollection, + setConsentData, +}; diff --git a/demoNative/app/app.css b/demoNative/app/app.css index 14de4823..abf98f9c 100644 --- a/demoNative/app/app.css +++ b/demoNative/app/app.css @@ -1,6 +1,76 @@ @import '@nativescript/theme/css/core.css'; @import '@nativescript/theme/css/default.css'; -Button.-primary { +/* Page styles */ + +.page { + background-color: #f9f9f9; +} + +/* Container styles */ +.container { + padding: 8; + vertical-align: middle; + margin: 8; +} + +/* ActionBar styles */ +.action-bar { + background-color: #3949AB; + color: #FFFFFF; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); +} + +.action-bar-title { + color: #FFFFFF; + font-weight: 300; +} + +/* Section styles */ +.section { + border-width: 1; + border-color: #ccc; + border-radius: 15; + overflow: hidden; + margin-bottom: 20; + background-color: #ffffff; +} + +.section-title { + background-color: #5C6BC0; + color: #ffffff; + padding: 15; + font-size: 20; + border-top-left-radius: 15; + border-top-right-radius: 15; + font-weight: bold; + text-align: center; +} + +.section-content { + padding: 20; + font-size: 16; + color: #555; +} + +/* Button styles */ +.button { + background-color: #7E57C2; + color: #ffffff; + font-weight: bold; font-size: 18; + border-radius: 15; + margin-top: 20; + margin-bottom: 8; /* Add space between buttons if they are stacked */ +} + +/* Buttons container */ +.buttons-container { + padding: 8; + width: 100%; } + +/* Ensure last button does not have margin at the bottom */ +.button:last-child { + margin-bottom: 0; +} \ No newline at end of file diff --git a/demoNative/app/main-page.xml b/demoNative/app/main-page.xml index 4a007d8f..86fc26a0 100644 --- a/demoNative/app/main-page.xml +++ b/demoNative/app/main-page.xml @@ -1,35 +1,54 @@ - - - - - - -