Skip to content

shwangMP/react-native-mparticle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-mparticle

npm version Standard - JavaScript Style Guide

Installation

First, download the library from npm:

$ npm install react-native-mparticle --save

Second, install the native dependencies. You can use rnpm (now part of react-native core via link) to add native dependencies automatically:

$ react-native link

Grab your mParticle key and secret from your app's dashboard and move on to the OS-specific instructions below.

iOS

Install the SDK using CocoaPods:

$ # Update your Podfile to depend on 'mParticle-Apple-SDK'
$ pod install

Start mParticle within application:didFinishLaunchingWithOptions::

[[MParticle sharedInstance] startWithKey:@"APP KEY" secret:@"APP SECRET"];

Android

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

Usage

Import

Importing the module:

import MParticle from 'react-native-mparticle'

Events

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' })

User Attributes

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')

User Identities

Setting user identities:

MParticle.setUserIdentity('example@example.com', MParticle.UserIdentityType.Email)

License

Apache 2.0

About

React Native module for mParticle

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 49.9%
  • Objective-C 25.8%
  • JavaScript 24.3%