@kirz/react-native-toolkit
Version:
Toolkit to speed up React Native development
132 lines (126 loc) • 6.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ApphudConnectorPlugin = void 0;
var _reactNativeApphud = _interopRequireWildcard(require("@kirz/react-native-apphud"));
var _reactNative = require("react-native");
var _Plugin = require("../Plugin");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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); }
class ApphudConnectorPlugin extends _Plugin.Plugin {
constructor() {
super(...arguments);
_defineProperty(this, "name", 'ApphudPlugin');
_defineProperty(this, "features", ['IAPReceiptValidator']);
_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) {
_reactNativeApphud.default.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 = _reactNative.Platform.select({
ios: _reactNativeApphud.IOSApphudAttributionProvider.AppsFlyer,
android: _reactNativeApphud.AndroidApphudAttributionProvider.appsFlyer
});
appsFlyer.getAppsFlyerUID((err, uid) => {
if (err) {
console.error(err);
return;
}
appsFlyer.onInstallConversionData(async res => {
try {
if (res.type === 'onInstallConversionDataLoaded') {
await _reactNativeApphud.default.addAttribution({
identifier: uid,
data: res.data,
attributionProviderId: ApphudAttributionProviderAppsFlyer
});
}
} catch (error) {
console.error(error);
}
});
appsFlyer.onInstallConversionFailure(async res => {
try {
if (res.type === 'onInstallConversionFailure') {
await _reactNativeApphud.default.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 = _reactNative.Platform.select({
ios: 3,
android: _reactNativeApphud.AndroidApphudAttributionProvider.facebook
});
await _reactNativeApphud.default.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 _reactNativeApphud.default.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) {
_reactNativeApphud.default.addAttribution({
data: {},
attributionProviderId: _reactNative.Platform.OS === 'ios' ? 4 : 'fireabse',
identifier: appInstanceId
});
}
})();
}
}
exports.ApphudConnectorPlugin = ApphudConnectorPlugin;
//# sourceMappingURL=ApphudConnectorPlugin.js.map