Using the Expo SDK

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

Initialization

Initialize the Linkrunner SDK in your App.tsx component:

You can find your project token here.

import linkrunner from "expo-linkrunner";
import { useEffect } from "react";

export default function App() {
    useEffect(() => {
        initLinkrunner();
    }, []);

    const initLinkrunner = async () => {
        await linkrunner.init("YOUR_PROJECT_TOKEN");
    };

    // Rest of your app
}

Getting Attribution Data

To retrieve attribution data and deeplink information related to an install:

const getAttributionInfo = async () => {
    const attributionData = await linkrunner.getAttributionData();
    console.log("Attribution data:", attributionData);
};

Response from linkrunner.getAttributionData

The method returns useful attribution information:

{
    deeplink: string; // The deeplink that led to the install
    campaign_data: {
        id: string; // Linkrunner Campaign ID
        name: string; // Campaign name
        type: "ORGANIC" | "INORGANIC";
        ad_network: string | null;
        group_name: string | null; // Ad group name
        asset_group_name: string | null; // Asset group name
        asset_name: string | null; // Asset name
        installed_at: string; // ISO timestamp of installation
        store_click_at: string; // ISO timestamp of store click
    }
    attribution_source: "ORGANIC" | "META" | "GOOGLE" | "INORGANIC";
}

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 () => {
    await linkrunner.signup({
        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
            amplitude_device_id: "amplitude_device_id", // Optional
            posthog_distinct_id: "posthog_distinct_id", // Optional
        },
        data: {}, // Optional: Any additional data
    });
};

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
        },
    });
};

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.

Function Placement Guide

FunctionWhere to PlaceWhen to Call
linkrunner.initApp.tsx within useEffectOnce when app starts
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
linkrunner.getAttributionDataAttribution handling logicWhen you need attribution data

Support

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