Using the React Native SDK

This guide will help you implement Linkrunner functionality in your React Native application.

Initialization

To initialize the Linkrunner SDK, add this code to your App.tsx component:

You can find your project token here.

SDK Signing Parameters (Optional)

For enhanced security, the LinkRunner SDK requires the following signing parameters during initialization:

  • secretKey: A unique secret key used for request signing and authentication
  • keyId: A unique identifier for the key pair used in the signing process

You can find your project token, secret key, and key ID here.

Note: The initialization method doesn’t return any value. To get attribution data and deeplink information, use the getAttributionData method.

import linkrunner from "rn-linkrunner";

// Inside your React component
useEffect(() => {
    init();
}, []); // Empty dependency array ensures it runs only once

const init = async () => {
    await linkrunner.init(
        token: "YOUR_PROJECT_TOKEN",
        keyId: "YOUR_KEY_ID", // Optional: Required for SDK signing
        secretKey: "YOUR_SECRET_KEY", // Optional: Required for SDK signing
    );
    console.log("Linkrunner initialized");
};

User Registration

Call the signup method once after the user has completed your app’s onboarding process:

It is strongly recommended to use the integrated platform’s identify function to set a persistent user_id once it becomes available (typically after signup or login).

If the platform’s identifier function is not called, you must provide a user identifier for Mixpanel, PostHog, and Amplitude integration.

  • mixpanel_distinct_id for Mixpanel
  • posthog_distinct_id for PostHog
  • amplitude_device_id for Amplitude
const onSignup = async () => {
    try {
        await linkrunner.signup({
            user_data: {
                id: "123", // Required: User ID
                name: "John Doe", // Optional
                phone: "9876543210", // Optional
                email: "user@example.com", // Optional
                // These properties are used to track reinstalls
                user_created_at: "2024-01-01T00:00:00Z", // Optional
                is_first_time_user: true, // Optional
                mixpanel_distinct_id: "mixpanel_distinct_id", // Optional - Mixpanel Distinct ID
                amplitude_device_id: "amplitude_device_id", // Optional - Amplitude User ID
                posthog_distinct_id: "posthog_distinct_id", // Optional - PostHog Distinct ID
            },
            data: {}, // Optional: Any additional data
        });
        console.log("Signup successful");
    } catch (error) {
        console.error("Error during signup:", error);
    }
};

Getting Attribution Data

To get attribution data and deeplink information for the current installation, use the getAttributionData function:

const getAttributionInfo = async () => {
    try {
        const attributionData = await linkrunner.getAttributionData();
        console.log("Attribution data:", attributionData);
    } catch (error) {
        console.error("Error getting attribution data:", error);
    }
};

The getAttributionData function returns:

{
    deeplink: string | null;
    campaign_data: {
        id: string;
        name: string;
        type: string; // "ORGANIC" | "INORGANIC"
        ad_network: string | null; // "META" | "GOOGLE" | null
        installed_at: string;
        store_click_at: string | null;
        group_name: string;
        asset_name: string;
        asset_group_name: string;
    };
    attribution_source: string;
}

Setting User Data

Call setUserData each time the app opens and the user is logged in:

const setUserData = async () => {
    await linkrunner.setUserData({
        user_data: {
            id: "123", // Required: User ID
            name: "John Doe", // Optional
            phone: "9876543210", // Optional
            email: "user@example.com", // Optional
            mixpanel_distinct_id: "mixpanel_distinct_id", // Optional - Mixpanel Distinct ID
            amplitude_device_id: "amplitude_device_id", // Optional - Amplitude User ID
            posthog_distinct_id: "posthog_distinct_id", // Optional - PostHog Distinct ID
        },
    });
};

Setting CleverTap ID

Use the setAdditionalData method to set CleverTap ID:

const setIntegrationData = async () => {
    await linkrunner.setAdditionalData({
        clevertapId: "YOUR_CLEVERTAP_USER_ID", // CleverTap user identifier
    });
};

Parameters for linkrunner.setAdditionalData

  • clevertapId: string (optional) - CleverTap user identifier

This method allows you to connect user identities across different analytics and marketing platforms.

Tracking Custom Events

Track custom events in your app:

const trackEvent = async () => {
    await linkrunner.trackEvent(
        "purchase_initiated", // Event name
        { product_id: "12345", category: "electronics" } // Optional: Event data
    );
};

Revenue Tracking

Capture Payment

Use this method to capture payment information:

const capturePayment = async () => {
    await linkrunner.capturePayment({
        amount: 100, // Payment amount
        userId: "user123", // User identifier
        paymentId: "payment456", // Optional: Unique payment identifier
        type: "FIRST_PAYMENT", // Optional: Payment type
        status: "PAYMENT_COMPLETED", // Optional: Payment status
    });
};

Parameters for linkrunner.capturePayment

  • amount: number (required) - The payment amount
  • userId: string (required) - Identifier for the user making the payment
  • paymentId: string (optional) - Unique identifier for the payment
  • type: string (optional) - Type of payment. Available options:
    • FIRST_PAYMENT - First payment made by the user
    • WALLET_TOPUP - Adding funds to a wallet
    • FUNDS_WITHDRAWAL - Withdrawing funds
    • SUBSCRIPTION_CREATED - New subscription created
    • SUBSCRIPTION_RENEWED - Subscription renewal
    • ONE_TIME - One-time payment
    • RECURRING - Recurring payment
    • DEFAULT - Default type (used if not specified)
  • status: string (optional) - Status of the payment. Available options:
    • PAYMENT_INITIATED - Payment has been initiated
    • PAYMENT_COMPLETED - Payment completed successfully (default if not specified)
    • PAYMENT_FAILED - Payment attempt failed
    • PAYMENT_CANCELLED - Payment was cancelled

Removing Payments

Remove payment records (for refunds or cancellations):

const removePayment = async () => {
    await linkrunner.removePayment({
        userId: "user123", // User identifier
        paymentId: "payment456", // Optional: Unique payment identifier
    });
};

Parameters for Linkrunner.removePayment

  • userId: String (required) - Identifier for the user whose payment is being removed
  • paymentId: String (optional) - Unique identifier for the payment to be removed

Note: Either paymentId or userId must be provided when calling removePayment. If only userId is provided, all payments for that user will be removed.

Enhanced Privacy Controls

The SDK offers options to enhance user privacy:

// Enable PII (Personally Identifiable Information) hashing
linkrunner.enablePIIHashing(true);

When PII hashing is enabled, sensitive user data like name, email, and phone number are hashed using SHA-256 before being sent to Linkrunner servers.

Function Placement Guide

FunctionWhere to PlaceWhen to Call
linkrunner.initApp.tsx within useEffectOnce when app starts
linkrunner.getAttributionDataAttribution data handling flowWhenever the attribution data is needed
linkrunner.setAdditionalDataIntegration codeWhen third-party integration IDs are available
linkrunner.signupOnboarding flowOnce after user completes onboarding
linkrunner.setUserDataAuthentication logicEvery time app opens with logged-in user
linkrunner.triggerDeeplinkAfter navigation initOnce after navigation is ready
linkrunner.trackEventThroughout appWhen specific user actions occur
linkrunner.capturePaymentPayment processingWhen user makes a payment
linkrunner.removePaymentRefund flowWhen payment needs to be removed

Support

If you encounter issues during integration, contact us at darshil@linkrunner.io.