UNPKG

appsonair-react-native-applink

Version:

A self-hosted dynamic link service for app download tracking, deep linking, and engagement analytics.

114 lines (109 loc) 4.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _exportNames = { initializeAppLink: true, createAppLink: true, getReferralDetails: true, onDeepLinkProcessed: true }; exports.onDeepLinkProcessed = exports.initializeAppLink = exports.getReferralDetails = exports.createAppLink = void 0; var _reactNative = require("react-native"); var _types = require("./types.js"); Object.keys(_types).forEach(function (key) { if (key === "default" || key === "__esModule") return; if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; if (key in exports && exports[key] === _types[key]) return; Object.defineProperty(exports, key, { enumerable: true, get: function () { return _types[key]; } }); }); const LINKING_ERROR = `The package 'appsonair-react-native-applink' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; const AppsonairReactNativeApplink = _reactNative.NativeModules.AppsonairReactNativeApplink ? _reactNative.NativeModules.AppsonairReactNativeApplink : new Proxy({}, { get() { throw new Error(LINKING_ERROR); } }); const emitter = _reactNative.NativeModules.AppsonairReactNativeApplink ? new _reactNative.NativeEventEmitter(_reactNative.NativeModules.AppsonairReactNativeApplink) : null; /** * Initializes the Appsonair React Native AppLink module. * Should be called once during app startup to set up deep link handling. * * @returns {Promise<boolean>} A promise that resolves to `true` if initialization succeeds. */ const initializeAppLink = async () => { return await AppsonairReactNativeApplink.initialize(); }; /** * Creates a new app link using the provided parameters. * The resulting app link can be used to navigate to specific content within the app. * * @param {AppLinkParams} params - Parameters used to generate the deep link. * @returns {Promise<CreateAppLinkResponse>} A promise that resolves to the generated deep link URL, or `null` if creation fails. */ exports.initializeAppLink = initializeAppLink; const createAppLink = async ({ url, name, urlPrefix, shortId = '', metaTitle = '', metaDescription = '', metaImageUrl = '', isOpenInBrowserAndroid = false, isOpenInAndroidApp = true, androidFallbackUrl = '', isOpenInBrowserApple = false, isOpenInIosApp = true, iOSFallbackUrl = '' }) => { const result = await AppsonairReactNativeApplink.createAppLink({ url, name, urlPrefix, shortId, metaTitle: metaTitle || null, metaDescription: metaDescription || null, metaImageUrl: metaImageUrl || null, isOpenInBrowserAndroid, isOpenInAndroidApp, androidFallbackUrl, isOpenInBrowserApple, isOpenInIosApp, iOSFallbackUrl }); if (typeof result === 'string') { return JSON.parse(result); } return result; }; /** * Fetches referral details from the Appsonair deep link service. * This method retrieves any available referral metadata associated with the user's session. * * @returns A Promise that resolves to an object containing referral details, or `null` if no referral data is available. */ exports.createAppLink = createAppLink; const getReferralDetails = async () => { return await AppsonairReactNativeApplink.getReferralDetails(); }; /** * Registers a listener for when a deep link is successfully processed. * The callback receives the processed deep link URL and any associated result data. * * @param {(event: { url: string; result: string }) => void} callback - Function to be called when a deep link is processed. * @returns {EmitterSubscription | null} An event subscription, or `null` if the listener could not be registered. */ exports.getReferralDetails = getReferralDetails; const onDeepLinkProcessed = callback => { return emitter?.addListener('onDeepLinkProcessed', callback) ?? null; }; exports.onDeepLinkProcessed = onDeepLinkProcessed; //# sourceMappingURL=index.js.map