affise-attribution-lib
TypeScript icon, indicating that this package has built-in type declarations

1.6.14 • Public • Published

Affise Attribution React Native Library

Package Version
affise-attribution-lib attribution

Description

Affise SDK is a software you can use to collect app usage statistics, device identifiers, deeplink usage, track install referrer.

Quick start

Integration

Integrate npm package

This is a Node.js module available through the npm registry.

Installation using npm

npm install affise-attribution-lib

Installation using yarn

yarn add affise-attribution-lib

Modules

If module start type is manual, then call:

Affise.moduleStart(AffiseModules.ADVERTISING)

Get list of installed modules:

Affise.getModulesInstalled().then((modules) => {
    console.log(`Modules: ${modules}`);
});

Android

Add modules to Android project

Module Version Start
ADVERTISING module-advertising Auto
NETWORK module-network Auto
PHONE module-phone Auto
STATUS module-status Auto

Example example/android/app/build.gradle

dependencies {
    // Affise modules
    implementation 'com.affise:module-advertising:1.6.26'
    implementation 'com.affise:module-network:1.6.26'
    implementation 'com.affise:module-phone:1.6.26'
    implementation 'com.affise:module-status:1.6.26'
}

iOS

Add modules to iOS project

Module Version Start
ADVERTISING 1.6.27 Manual
STATUS 1.6.27 Auto

Example example/ios/Podfile

target 'YourAppProject' do
  # ...

  # Affise Modules
  pod 'AffiseModule/Advertising', `1.6.27`
  pod 'AffiseModule/Status', `1.6.27`
end

Warning

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

Module Advertising requires NSUserTrackingUsageDescription key in info.plist

Application will crash if key not present

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

Open info.plist and add key NSUserTrackingUsageDescription with string value. For more information read requirements

Initialize

After dependency is added, and project is sync with npm install and initialize.

Demo app App.tsx

import {
  Affise,
  AffiseInitProperties
} from 'affise-attribution-lib';


export default function App() {

    React.useEffect(() => {
        Affise
            .settings({
                affiseAppId: 'Your appId', //Change to your app id
                secretKey: 'Your SDK secretKey', //Change to your SDK secretKey
            })
            .start(); // Start Affise SDK
    });

    return (
        <SafeAreaView>
        </SafeAreaView>
    );
}

Check if library is initialized

Affise.isInitialized();

Domain

Set SDK server domain:

Affise
    .settings({
        affiseAppId: 'Your appId',
        secretKey: 'Your SDK secretKey',
    })
    .setDomain("https://YoureCustomDomain/") // Set custom domain
    .start(); // Start Affise SDK

Requirements

Android

Minimal Android SDK version is 21

For a minimal working functionality your app needs to declare internet permission:

<manifest>
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

OAID certificate in your project (Optional) example/android/app/src/main/assets/oaid.cert.pem

iOS

Affise Advertising module uses AppTrackingTransparency framework to get advertisingIdentifier For working functionality your app needs to declare NSUserTrackingUsageDescription permission:

Open XCode project info.plist and add key NSUserTrackingUsageDescription with string value

Example info.plist:

<plist version="1.0">
<dict>
    ...
	<key>NSUserTrackingUsageDescription</key>
	<string>Youre permission text</string>
</dict>

Features

ProviderType identifiers collection

To match users with events and data library is sending, these ProviderType identifiers are collected:

Attribution

  • AFFISE_APP_ID
  • AFFISE_PKG_APP_NAME
  • AFF_APP_NAME_DASHBOARD
  • APP_VERSION
  • APP_VERSION_RAW
  • STORE
  • TRACKER_TOKEN
  • TRACKER_NAME
  • FIRST_TRACKER_TOKEN
  • FIRST_TRACKER_NAME
  • LAST_TRACKER_TOKEN
  • LAST_TRACKER_NAME
  • OUTDATED_TRACKER_TOKEN
  • INSTALLED_TIME
  • FIRST_OPEN_TIME
  • INSTALLED_HOUR
  • FIRST_OPEN_HOUR
  • INSTALL_FIRST_EVENT
  • INSTALL_BEGIN_TIME
  • INSTALL_FINISH_TIME
  • REFERRER_INSTALL_VERSION
  • REFERRAL_TIME
  • REFERRER_CLICK_TIME
  • REFERRER_CLICK_TIME_SERVER
  • REFERRER_GOOGLE_PLAY_INSTANT
  • CREATED_TIME
  • CREATED_TIME_MILLI
  • CREATED_TIME_HOUR
  • UNINSTALL_TIME
  • REINSTALL_TIME
  • LAST_SESSION_TIME
  • CPU_TYPE
  • HARDWARE_NAME
  • DEVICE_MANUFACTURER
  • DEEPLINK_CLICK
  • DEVICE_ATLAS_ID
  • AFFISE_DEVICE_ID
  • AFFISE_ALT_DEVICE_ID
  • ANDROID_ID
  • ANDROID_ID_MD5
  • REFTOKEN
  • REFTOKENS
  • REFERRER
  • USER_AGENT
  • MCCODE
  • MNCODE
  • REGION
  • COUNTRY
  • LANGUAGE
  • DEVICE_NAME
  • DEVICE_TYPE
  • OS_NAME
  • PLATFORM
  • SDK_PLATFORM
  • API_LEVEL_OS
  • AFFISE_SDK_VERSION
  • OS_VERSION
  • RANDOM_USER_ID
  • AFFISE_SDK_POS
  • TIMEZONE_DEV
  • AFFISE_EVENT_NAME
  • AFFISE_EVENT_TOKEN
  • LAST_TIME_SESSION
  • TIME_SESSION
  • AFFISE_SESSION_COUNT
  • LIFETIME_SESSION_COUNT
  • AFFISE_DEEPLINK
  • AFFISE_PART_PARAM_NAME
  • AFFISE_PART_PARAM_NAME_TOKEN
  • AFFISE_APP_TOKEN
  • LABEL
  • AFFISE_SDK_SECRET_ID
  • UUID
  • AFFISE_APP_OPENED
  • PUSHTOKEN
  • AFFISE_EVENTS_COUNT
  • AFFISE_SDK_EVENTS_COUNT
  • AFFISE_METRICS_EVENTS_COUNT
  • AFFISE_INTERNAL_EVENTS_COUNT
  • IS_ROOTED
  • IS_EMULATOR

Advertising

  • GAID_ADID
  • GAID_ADID_MD5
  • OAID
  • OAID_MD5
  • ADID
  • ALTSTR_ADID
  • FIREOS_ADID
  • COLOROS_ADID

Network

  • MAC_SHA1
  • MAC_MD5
  • CONNECTION_TYPE
  • PROXY_IP_ADDRESS

Phone

  • NETWORK_TYPE
  • ISP

Events tracking

Demo app DefaultEventsFactory.ts

For example, we want to track what items usually user adds to shopping cart. To send event first create it with following code

import { Affise, AddToCartEvent } from 'affise-attribution-lib';

class Presenter {
  onUserAddsItemsToCart(item: string) {
    const items = {
      items: 'cookies, potato, milk',
    };

    new AddToCartEvent({
        userData: item,
        timeStampMillis: Date.now()
    })
        .addPredefinedString(PredefinedString.DESCRIPTION, 'groceries')
        .addPredefinedObject(PredefinedObject.CONTENT, items)
        .send();
  }
}

With above example you can implement other events:

  • AchieveLevel
  • AddPaymentInfo
  • AddToCart
  • AddToWishlist
  • AdRevenue
  • ClickAdv
  • CompleteRegistration
  • CompleteStream
  • CompleteTrial
  • CompleteTutorial
  • Contact
  • ContentItemsView
  • CustomizeProduct
  • DeepLinked
  • Donate
  • FindLocation
  • InitiateCheckout
  • InitiatePurchase
  • InitiateStream
  • Invite
  • LastAttributedTouch
  • Lead
  • ListView
  • Login
  • OpenedFromPushNotification
  • Order
  • OrderItemAdded
  • OrderItemRemove
  • OrderCancel
  • OrderReturnRequest
  • OrderReturnRequestCancel
  • Purchase
  • Rate
  • ReEngage
  • Reserve
  • Sales
  • Schedule
  • Search
  • Share
  • SpendCredits
  • StartRegistration
  • StartTrial
  • StartTutorial
  • SubmitApplication
  • Subscribe
  • TravelBooking
  • UnlockAchievement
  • Unsubscribe
  • Update
  • ViewAdv
  • ViewCart
  • ViewContent
  • ViewItem
  • ViewItems
  • InitialSubscription
  • InitialTrial
  • InitialOffer
  • ConvertedTrial
  • ConvertedOffer
  • TrialInRetry
  • OfferInRetry
  • SubscriptionInRetry
  • RenewedSubscription
  • FailedSubscriptionFromRetry
  • FailedOfferFromRetry
  • FailedTrialFromRetry
  • FailedSubscription
  • FailedOfferise
  • FailedTrial
  • ReactivatedSubscription
  • RenewedSubscriptionFromRetry
  • ConvertedOfferFromRetry
  • ConvertedTrialFromRetry
  • Unsubscription

Custom events tracking

Use any of custom events if default doesn't fit your scenario:

  • CustomId01
  • CustomId02
  • CustomId03
  • CustomId04
  • CustomId05
  • CustomId06
  • CustomId07
  • CustomId08
  • CustomId09
  • CustomId10

If above event functionality still limits your usecase, you can use UserCustomEvent

new UserCustomEvent({eventName: "MyCustomEvent"})
    .send();

Predefined event parameters

To enrich your event with another dimension, you can use predefined parameters for most common cases. Add it to any event:

import {
  Affise,
  AddToCartEvent,
  PredefinedString,
  PredefinedObject,
} from 'affise-attribution-lib';

class Presenter {
  onUserAddsItemsToCart(item: string) {
    const items = {
      items: 'cookies, potato, milk',
    };

    new AddToCartEvent({
        userData: item,
    })
        .addPredefinedString(PredefinedString.DESCRIPTION, 'best before 2029')
        .addPredefinedObject(PredefinedObject.CONTENT, items)
        .send();
  }
}

In examples above PredefinedString.DESCRIPTION and PredefinedObject.CONTENT is used, but many others is available:

PredefinedParameter Type
PredefinedString string
PredefinedLong bigint
PredefinedFloat number
PredefinedObject Record<string, unknown>
PredefinedListObject Array<Record<string, unknown>>
PredefinedListString Array<string>

PredefinedString

  • ACHIEVEMENT_ID
  • ADREV_AD_TYPE
  • BRAND
  • BRICK
  • CAMPAIGN_ID
  • CATALOGUE_ID
  • CHANNEL_TYPE
  • CITY
  • CLASS
  • CLICK_ID
  • CONTENT_ID
  • CONTENT_NAME
  • CONTENT_TYPE
  • CONVERSION_ID
  • COUNTRY
  • COUPON_CODE
  • CURRENCY
  • CUSTOMER_SEGMENT
  • CUSTOMER_TYPE
  • CUSTOMER_USER_ID
  • DEEP_LINK
  • DESCRIPTION
  • DESTINATION_A
  • DESTINATION_B
  • DESTINATION_LIST
  • EVENT_NAME
  • NEW_VERSION
  • NETWORK
  • OLD_VERSION
  • ORDER_ID
  • PARAM_01
  • PARAM_02
  • PARAM_03
  • PARAM_04
  • PARAM_05
  • PARAM_06
  • PARAM_07
  • PARAM_08
  • PARAM_09
  • PARAM_10
  • PAYMENT_INFO_AVAILABLE
  • PID
  • PLACEMENT
  • PREFERRED_NEIGHBORHOODS
  • PRODUCT_ID
  • PRODUCT_NAME
  • PURCHASE_CURRENCY
  • RECEIPT_ID
  • REGION
  • REGISTRATION_METHOD
  • REVIEW_TEXT
  • SEARCH_STRING
  • SEGMENT
  • SOURCE
  • STATUS
  • SUBSCRIPTION_ID
  • SUCCESS
  • SUGGESTED_DESTINATIONS
  • SUGGESTED_HOTELS
  • TUTORIAL_ID
  • UNIT
  • UTM_CAMPAIGN
  • UTM_MEDIUM
  • UTM_SOURCE
  • VALIDATED
  • VERTICAL
  • VIRTUAL_CURRENCY_NAME
  • VOUCHER_CODE

PredefinedLong

  • AMOUNT
  • DATE_A
  • DATE_B
  • DEPARTING_ARRIVAL_DATE
  • DEPARTING_DEPARTURE_DATE
  • HOTEL_SCORE
  • LEVEL
  • MAX_RATING_VALUE
  • NUM_ADULTS
  • NUM_CHILDREN
  • NUM_INFANTS
  • PREFERRED_NUM_STOPS
  • PREFERRED_STAR_RATINGS
  • QUANTITY
  • RATING_VALUE
  • RETURNING_ARRIVAL_DATE
  • RETURNING_DEPARTURE_DATE
  • SCORE
  • TRAVEL_START
  • TRAVEL_END
  • USER_SCORE
  • EVENT_START
  • EVENT_END

PredefinedFloat

  • PREFERRED_PRICE_RANGE
  • PRICE
  • REVENUE
  • LAT
  • LONG

PredefinedObject

  • CONTENT

PredefinedListObject

  • CONTENT_LIST

PredefinedListString

  • CONTENT_IDS

Events buffering

Affise library will send any pending events with first opportunity, but if there is no network connection or device is disabled, events are kept locally for 7 days before deletion.

Advertising Identifier (google) tracking

Advertising Identifier (google) tracking is supported automatically, no actions needed

Open Advertising Identifier (huawei) tracking

Open Advertising Identifier is supported automatically, no actions needed

Install referrer tracking

Install referrer tracking is supported automatically, no actions needed

Push token tracking

To let affise track push token you need to receive it from your push service provider, and pass to Affise library. First add firebase integration to your app completing these steps: Firebase Docs

After you have done with firebase integration, add to your cloud messaging service onNewToken method Affise.addPushToken(token)

import { Affise } from 'affise-attribution-lib';
import messaging from '@react-native-firebase/messaging';

const getToken = async () => {
  const token = await messaging().getToken();
  if (token) {
    Affise.addPushToken(token);
  }
};

Reinstall Uninstall tracking

Affise automatically track reinstall events by using silent-push technology, to make this feature work, pass push token when it is recreated by user and on you application starts up

Affise.addPushToken(token);

APK preinstall tracking

SDK is also supports scenario when APK is installed not from one of application markets, such as google play, huawei appgallery or amazon appstore To use this feature, create file with name partner_key in your app assets directory, and write unique identifier inside, this key will be passed to our backend so you can track events by partner later in your Affise console.

Deeplinks

Register deeplink callback right after Affise.settings({affiseAppId, secretKey}).start()

Affise.registerDeeplinkCallback((uri) => {
    // Handle deeplink
});

Android

To integrate deeplink support in android you need:

Add intent filter to AndroidManifest.xml as in example/android/app/src/main/AndroidManifest.xml,

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data
        android:host="YOUR_DOMAIN"
        android:scheme="react" />
</intent-filter>

iOS

To integrate deeplink support in iOS you need:

Add deeplink handler to AppDelegate.mm as in example/ios/AffiseAttributionLibExample/AppDelegate.mm

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [RCTLinkingManager application:application openURL:url
                      sourceApplication:sourceApplication annotation:annotation];
}

Add key CFBundleURLTypes to Info.plist

Example: example/ios/AffiseAttributionLibExample/Info.plist

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>YOUR_DOMAIN</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>react</string>
        </array>
    </dict>
</array>

Offline mode

In some scenarios you would want to limit Affise network usage, to pause that activity call anywhere in your application following code after Affise start:

Affise.settings({affiseAppId, secretKey}).start(); // Start Affise SDK
Affise.setOfflineModeEnabled(true); // to enable offline mode
Affise.setOfflineModeEnabled(false); // to disable offline mode

While offline mode is enabled, your metrics and other events are kept locally, and will be delivered once offline mode is disabled. Offline mode is persistent as Application lifecycle, and will be disabled with process termination automatically. To check current offline mode status call:

Affise.isOfflineModeEnabled().then((enabled) => {
    // returns true or false describing current offline Mode state
});

Disable tracking

To disable any tracking activity, storing events and gathering device identifiers and metrics call anywhere in your application following code after Affise start:

Affise.settings({affiseAppId, secretKey}).start(); // Start Affise SDK
Affise.setTrackingEnabled(true); // to enable tracking
Affise.setTrackingEnabled(false); // to disable tracking

By default, tracking is enabled.

While tracking mode is disabled, metrics and other identifiers is not generated locally. Keep in mind that this flag is persistent until app reinstall, and don't forget to reactivate tracking when needed. To check current status of tracking call:

Affise.isTrackingEnabled().then((enabled) => {
  // returns true or false describing current tracking state
});

Disable background tracking

To disable any background tracking activity, storing events and gathering device identifiers and metrics call anywhere in your application following code after Affise start:

Affise.settings({affiseAppId, secretKey}).start(); // Start Affise SDK
Affise.setBackgroundTrackingEnabled(true); // to enable background tracking
Affise.setBackgroundTrackingEnabled(false); // to disable background tracking

By default, background tracking is enabled.

While background tracking mode is disabled, metrics and other identifiers is not generated locally. Background tracking mode is persistent as Application lifecycle, and will be re-enabled with process termination automatically. To check current status of background tracking call:

Affise.isBackgroundTrackingEnabled().then((enabled) => {
  // returns true or false describing current background tracking state
});

Get random user Id

Affise.getRandomUserId();

Get random device Id

Affise.getRandomDeviceId();

Get providers

Returns providers map with ProviderType as key

As Promise:

Affise.getProviders().then((providers) => {
    const key = ProviderType.AFFISE_APP_TOKEN;
    const value = providers[key];
    // handle provider value
});

As async / await:

const fetchData = async () => {
    const providers = await Affise.getProviders();
    const key = ProviderType.AFFISE_APP_TOKEN;
    const value = providers[key];
    // handle provider value
};

fetchData()
    .catch(console.error);

Is first run

Affise.isFirstRun().then((isFirstRun) => {
  // handle
});

Get referrer

Use the next public method of SDK

Affise.getReferrer().then((referrer) => {
  // handle referrer
});

Get referrer value

Use the next public method of SDK to get referrer value by

Affise.getReferrerValue(ReferrerKey.CLICK_ID, (value) => {
  // handle referrer
})

Referrer keys

In examples above ReferrerKey.CLICK_ID is used, but many others is available:

  • AD_ID
  • CAMPAIGN_ID
  • CLICK_ID
  • AFFISE_AD
  • AFFISE_AD_ID
  • AFFISE_AD_TYPE
  • AFFISE_ADSET
  • AFFISE_ADSET_ID
  • AFFISE_AFFC_ID
  • AFFISE_CHANNEL
  • AFFISE_CLICK_LOOK_BACK
  • AFFISE_COST_CURRENCY
  • AFFISE_COST_MODEL
  • AFFISE_COST_VALUE
  • AFFISE_DEEPLINK
  • AFFISE_KEYWORDS
  • AFFISE_MEDIA_TYPE
  • AFFISE_MODEL
  • AFFISE_OS
  • AFFISE_PARTNER
  • AFFISE_REF
  • AFFISE_SITE_ID
  • AFFISE_SUB_SITE_ID
  • AFFISE_SUB_1
  • AFFISE_SUB_2
  • AFFISE_SUB_3
  • AFFISE_SUB_4
  • AFFISE_SUB_5
  • AFFC
  • PID
  • SUB_1
  • SUB_2
  • SUB_3
  • SUB_4
  • SUB_5

Get module state

Affise.getStatus(AffiseModules.STATUS, (response) => {
    // handle status response
});

Platform specific

GDPR right to be forgotten

Android Only

Under the EU's General Data Protection Regulation (GDPR): An individual has the right to have their personal data erased. To provide this functionality to user, as the app developer, you can call

Affise.settings({affiseAppId, secretKey}).start(); // Start Affise SDK
Affise.android.forget(); // to forget users data

After processing such request our backend servers will delete all user's data. To prevent library from generating new events, disable tracking just before calling Affise.forget:

Affise.settings({affiseAppId, secretKey}).start(); // Start Affise SDK
Affise.setTrackingEnabled(false);
Affise.android.forget(); // to forget users data

StoreKit Ad Network

iOS Only

For ios prior 16.1 first call

Affise.ios.registerAppForAdNetworkAttribution((error) => {
  // Handle error
});

Updates the fine and coarse conversion values, and calls a completion handler if the update fails. Second argument coarseValue is available in iOS 16.1+

Affise.ios.updatePostbackConversionValue(1n, SKAdNetwork.CoarseConversionValue.medium, (error) => {
  // Handle error
});

Configure your app to send postback copies to Affise:

Add key NSAdvertisingAttributionReportEndpoint to Info.plist Set key value to https://affise-skadnetwork.com/

Example: example/ios/AffiseAttributionLibExample/Info.plist

<key>CFBundleURLTypes</key>
<array>
    <dict>
      <key>NSAdvertisingAttributionReportEndpoint</key>
      <string>https://affise-skadnetwork.com/</string>
    </dict>
</array>

SDK to SDK integrations

// Send AdRevenue info
new AffiseAdRevenue(AffiseAdSource.ADMOB)
        .setRevenue(2.5, "ImpressionData_Currency")
        .setNetwork("ImpressionData_Network")
        .setUnit("ImpressionData_Unit")
        .setPlacement("ImpressionData_Placement")
        .send();

Debug

Validate credentials

Warning

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

Debug methods WON'T work on Production

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

Validate your credentials by receiving ValidationStatus values:

  • VALID - your credentials are valid
  • INVALID_APP_ID - your app id is not valid
  • INVALID_SECRET_KEY - your SDK secretKey is not valid
  • PACKAGE_NAME_NOT_FOUND - your application package name not found
  • NOT_WORKING_ON_PRODUCTION - you using debug method on production
  • NETWORK_ERROR - network or server not available (for example Airoplane mode is active)
Affise
    .settings({
        affiseAppId: 'Your appId',
        secretKey: 'Your SDK secretKey',
    })
    .setProduction(false) //To enable debug methods set Production to false
    .start(); // Start Affise SDK

Affise.debug.validate((status) =>
{
    // Handle validation status
});

Troubleshoots

iOS

Warning

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

This app has crashed because Affise Advertising Module is attempted to access privacy-sensitive data without a usage description.

The app's Info.plist must contain an NSUserTrackingUsageDescription key with a string value explaining

to the user how the app uses this data.

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

Open info.plist and add key NSUserTrackingUsageDescription with string value. For more information read requirements

Package Sidebar

Install

npm i affise-attribution-lib

Homepage

affise.com

Weekly Downloads

1

Version

1.6.14

License

MIT

Unpacked Size

759 kB

Total Files

1003

Last publish

Collaborators

  • affise