@kirz/react-native-toolkit
Version:
Toolkit to speed up React Native development
123 lines (118 loc) • 4.79 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 ApphudSdk, { AndroidApphudAttributionProvider, IOSApphudAttributionProvider } from '@kirz/react-native-apphud';
import { Platform } from 'react-native';
import { Plugin } from '../Plugin';
export class ApphudConnectorPlugin extends Plugin {
constructor() {
super(...arguments);
_defineProperty(this, "name", 'ApphudPlugin');
_defineProperty(this, "features", []);
_defineProperty(this, "initializationTimeout", 15000);
}
async initialize(bundle) {
// ApphudSdk.setAdvertisingIdentifier(true);
// Send IDFA to Apphud
(async () => {
const idfaPlugin = bundle.get('IdfaPlugin');
if (idfaPlugin !== null && idfaPlugin !== void 0 && idfaPlugin.idfa) {
ApphudSdk.setAdvertisingIdentifier(idfaPlugin.idfa);
}
})();
// Connect AppsFlyer to AppHud
(async () => {
var _bundle$get;
const appsFlyer = (_bundle$get = bundle.get('AppsFlyerPlugin')) === null || _bundle$get === void 0 ? void 0 : _bundle$get.instance;
if (!appsFlyer) {
return;
}
const ApphudAttributionProviderAppsFlyer = Platform.select({
ios: IOSApphudAttributionProvider.AppsFlyer,
android: AndroidApphudAttributionProvider.appsFlyer
});
appsFlyer.getAppsFlyerUID((err, uid) => {
if (err) {
console.error(err);
return;
}
appsFlyer.onInstallConversionData(async res => {
try {
if (res.type === 'onInstallConversionDataLoaded') {
await ApphudSdk.addAttribution({
identifier: uid,
data: res.data,
attributionProviderId: ApphudAttributionProviderAppsFlyer
});
}
} catch (error) {
console.error(error);
}
});
appsFlyer.onInstallConversionFailure(async res => {
try {
if (res.type === 'onInstallConversionFailure') {
await ApphudSdk.addAttribution({
identifier: uid,
data: {
error: res.data
},
attributionProviderId: ApphudAttributionProviderAppsFlyer
});
}
} catch (error) {
console.error(error);
}
});
});
})();
// Connect Facebook to AppHud
(async () => {
var _bundle$get2;
const idfaPlugin = bundle.get('IdfaPlugin');
const facebook = (_bundle$get2 = bundle.get('FacebookPlugin')) === null || _bundle$get2 === void 0 ? void 0 : _bundle$get2.instance;
if (!facebook) {
return;
}
const ApphudAttributionProviderFacebook = Platform.select({
ios: 3,
android: AndroidApphudAttributionProvider.facebook
});
await ApphudSdk.addAttribution({
identifier: null,
data: {},
attributionProviderId: ApphudAttributionProviderFacebook
});
if (idfaPlugin !== null && idfaPlugin !== void 0 && idfaPlugin.idfa) {
facebook.setAdvertiserTrackingEnabled(true);
}
})();
// Connect Branch to AppHud
(async () => {
var _bundle$get3;
const branch = (_bundle$get3 = bundle.get('BranchPlugin')) === null || _bundle$get3 === void 0 ? void 0 : _bundle$get3.instance;
if (!branch) {
return;
}
const deviceId = await ApphudSdk.userId();
branch.default.setIdentity(deviceId);
})();
// Connect Firebase to AppHud
(async () => {
var _bundle$get4;
const firebase = (_bundle$get4 = bundle.get('FirebasePlugin')) === null || _bundle$get4 === void 0 ? void 0 : _bundle$get4.instance;
if (!firebase) {
return;
}
const appInstanceId = await firebase.analytics.getAppInstanceId();
if (appInstanceId) {
ApphudSdk.addAttribution({
data: {},
attributionProviderId: Platform.OS === 'ios' ? 4 : 'fireabse',
identifier: appInstanceId
});
}
})();
}
}
//# sourceMappingURL=ApphudConnectorPlugin.js.map