First, download the library from npm:
$ npm install react-native-mparticle --saveSecond, install the native dependencies. You can use rnpm (now part of react-native core via link) to add native dependencies automatically:
$ react-native linkGrab your mParticle key and secret from your app's dashboard and move on to the OS-specific instructions below.
Install the SDK using CocoaPods:
$ # Update your Podfile to depend on 'mParticle-Apple-SDK'
$ pod installStart mParticle within application:didFinishLaunchingWithOptions::
[[MParticle sharedInstance] startWithKey:@"APP KEY" secret:@"APP SECRET"];Add your key and secret as string resources in your app:
<?xml version="1.0" encoding="utf-8" ?>
<!-- ex. src/main/res/values/mparticle.xml -->
<resources>
<string name="mp_key">APP KEY</string>
<string name="mp_secret">APP SECRET</string>
</resources>Start mParticle in your application's onCreate:
MParticle.start(this);Importing the module:
import MParticle from 'react-native-mparticle'Logging events:
MParticle.logEvent('Test event', MParticle.EventType.Other, { 'Test key': 'Test value' })Logging commerce events:
const product = new MParticle.Product('Test product for cart', '1234', 19.99)
const transactionAttributes = new MParticle.TransactionAttributes('Test transaction id')
const event = MParticle.CommerceEvent.createProductActionEvent(MParticle.ProductActionType.AddToCart, [product], transactionAttributes)
MParticle.logCommerceEvent(event)const promotion = new MParticle.Promotion('Test promotion id', 'Test promotion name', 'Test creative', 'Test position')
const event = MParticle.CommerceEvent.createPromotionEvent(MParticle.PromotionActionType.View, [promotion])
MParticle.logCommerceEvent(event)const product = new MParticle.Product('Test product that was viewed', '5678', 29.99)
const impression = new MParticle.Impression('Test impression list name', [product])
const event = MParticle.CommerceEvent.createImpressionEvent([impression])
MParticle.logCommerceEvent(event)Logging screen events:
MParticle.logScreenEvent('Test screen', { 'Test key': 'Test value' })Setting user attributes and tags:
MParticle.setUserAttribute('Test key', 'Test value')MParticle.setUserAttribute(MParticle.UserAttributeType.FirstName, 'Test first name')MParticle.setUserAttributeArray('Test key', ['Test value 1', 'Test value 2'])MParticle.setUserTag('Test key')MParticle.removeUserAttribute('Test key')Setting user identities:
MParticle.setUserIdentity('example@example.com', MParticle.UserIdentityType.Email)Apache 2.0