@kirz/react-native-toolkit
Version:
Toolkit to speed up React Native development
57 lines • 3.49 kB
JavaScript
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import appsFlyer from 'react-native-appsflyer';
import { Plugin } from '../Plugin';
export class AppsFlyerPlugin extends Plugin {
get instance() {
return appsFlyer;
}
constructor(options, callbacks) {
super();
this.options = options;
this.callbacks = callbacks;
_defineProperty(this, "name", 'AppsFlyerPlugin');
_defineProperty(this, "features", ['Analytics']);
_defineProperty(this, "initializationTimeout", 5000);
}
async initialize() {
var _this$callbacks, _this$callbacks2, _this$callbacks3, _this$callbacks4, _this$callbacks5;
if ((_this$callbacks = this.callbacks) !== null && _this$callbacks !== void 0 && _this$callbacks.onAppOpenAttribution) {
appsFlyer.onAppOpenAttribution(this.callbacks.onAppOpenAttribution);
}
if ((_this$callbacks2 = this.callbacks) !== null && _this$callbacks2 !== void 0 && _this$callbacks2.onAttributionFailure) {
appsFlyer.onAttributionFailure(this.callbacks.onAttributionFailure);
}
if ((_this$callbacks3 = this.callbacks) !== null && _this$callbacks3 !== void 0 && _this$callbacks3.onDeepLink) {
appsFlyer.onDeepLink(this.callbacks.onDeepLink);
}
appsFlyer.onInstallConversionData(((_this$callbacks4 = this.callbacks) === null || _this$callbacks4 === void 0 ? void 0 : _this$callbacks4.onInstallConversionData) ?? (() => {}));
if ((_this$callbacks5 = this.callbacks) !== null && _this$callbacks5 !== void 0 && _this$callbacks5.onInstallConversionFailure) {
appsFlyer.onInstallConversionFailure(this.callbacks.onInstallConversionFailure);
}
await new Promise((resolve, reject) => {
appsFlyer.initSdk({
isDebug: false,
onInstallConversionDataListener: true,
onDeepLinkListener: true,
timeToWaitForATTUserAuthorization: 10,
// for iOS 14.5
...this.options
}, result => {
var _this$callbacks6, _this$callbacks6$onIn;
resolve();
(_this$callbacks6 = this.callbacks) === null || _this$callbacks6 === void 0 ? void 0 : (_this$callbacks6$onIn = _this$callbacks6.onInitSuccess) === null || _this$callbacks6$onIn === void 0 ? void 0 : _this$callbacks6$onIn.call(_this$callbacks6, result);
}, error => {
var _this$callbacks7, _this$callbacks7$onIn;
console.error(error);
reject(error);
(_this$callbacks7 = this.callbacks) === null || _this$callbacks7 === void 0 ? void 0 : (_this$callbacks7$onIn = _this$callbacks7.onInitFailure) === null || _this$callbacks7$onIn === void 0 ? void 0 : _this$callbacks7$onIn.call(_this$callbacks7, error);
});
});
}
async logEvent(event, parameters) {
await appsFlyer.logEvent(event, parameters);
}
}
//# sourceMappingURL=AppsFlyerPlugin.js.map