react-native-mparticle 2.4.12 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ name: Release SDK
2
+
3
+ on:
4
+ workflow_dispatch
5
+ jobs:
6
+ # SDK release is done from public/master branch.
7
+ confirm-master-branch:
8
+ name: Confirm release is run on public/master branch
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Git checkout
12
+ uses: actions/checkout@v1
13
+ - name: Branch name
14
+ run: |
15
+ BRANCHNAME=${GITHUB_REF##*/}
16
+ echo "pulling branch name, branch name is:"
17
+ echo $BRANCHNAME
18
+ if [ $BRANCHNAME != "master" ]
19
+ then
20
+ echo "You can only run a release from the master branch, you are trying to run it from ${BRANCHNAME}"
21
+ exit 1
22
+ fi
23
+
24
+ # All new code is stored in internal/development. Release from public/master will merge changes from internal/development into
25
+ # public/master, then run semantic-release on public/master to update changelog and release notes. Before semantic-release publishes
26
+ # to npm, it builds the dist/ folder. Finally, commits from public/master are synced back to internal/master and internal/development.
27
+
28
+ react-tests:
29
+ name: Run React Native Unit Tests
30
+ runs-on: ubuntu-18.04
31
+ needs: ['confirm-master-branch']
32
+ steps:
33
+ - name: Checkout
34
+ uses: actions/checkout@v2
35
+ - uses: actions/setup-node@master
36
+ - uses: c-hive/gha-yarn-cache@v1
37
+
38
+ - name: Install node modules
39
+ run: yarn install
40
+
41
+ - name: Run test
42
+ run: yarn test
43
+
44
+ android-unit-tests:
45
+ name: Run Android Unit Tests
46
+ runs-on: ubuntu-18.04
47
+ needs: ['confirm-master-branch']
48
+ steps:
49
+ - name: Checkout
50
+ uses: actions/checkout@v2
51
+
52
+ - name: Run Android Unit Tests
53
+ run: echo "pwd"; pwd; echo "ls:"; ls; cd android; ./gradlew test
54
+
55
+
56
+ release-and-sync-repos:
57
+ name: Release and Sync Repos
58
+ runs-on: ubuntu-18.04
59
+ needs: ['android-unit-tests', 'react-tests']
60
+ steps:
61
+ - name: Checkout internal/development
62
+ uses: actions/checkout@v2
63
+
64
+ - name: Setup Node.js
65
+ uses: actions/setup-node@v1
66
+ with:
67
+ node-version: 12.x
68
+
69
+ - name: Install node modules
70
+ run: yarn install
71
+
72
+ - name: Release
73
+ run: ./release.sh ${{ secrets.NPM_TOKEN}}
package/README.md CHANGED
@@ -3,38 +3,58 @@
3
3
  [![npm version](https://badge.fury.io/js/react-native-mparticle.svg)](https://badge.fury.io/js/react-native-mparticle)
4
4
  [![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](http://standardjs.com/)
5
5
 
6
+ React Native allows developers to use a single code base to deploy features to multiple platforms. With the mParticle React Native library, you can leverage a single API to deploy your data to hundreds of integrations from your iOS and Android apps.
7
+
8
+ ### Supported Features
9
+ | Method | Android | iOS |
10
+ | --- | --- | --- |
11
+ | Custom Events | <li> [X] </li> | <li> [X] </li> |
12
+ | Page Views | <li> [X] </li> | <li> [X] </li> |
13
+ | Identity | <li> [X] </li> | <li> [X] </li> |
14
+ | eCommerce | <li> [X] </li> | <li> [X] </li> |
15
+ | Consent | <li> [X] </li> | <li> [X] </li> |
16
+
6
17
  # Installation
7
18
 
8
- **First, download the library** from npm:
19
+ 1. **Download and install the mParticle React Native library** from npm:
9
20
 
10
21
  ```bash
11
22
  $ npm install react-native-mparticle --save
12
23
  ```
13
24
 
14
- **Second, install the native dependencies**. You can use `rnpm` (now part of `react-native` core via `link`) to add native dependencies automatically:
25
+ 2. **Install the native dependencies**. You can use `rnpm` (now part of `react-native` core via `link`) to add native dependencies automatically:
15
26
 
16
27
  ```bash
17
28
  $ react-native link
18
29
  ```
19
30
 
20
- **Grab your mParticle key and secret** from [your app's dashboard][1] and move on to the OS-specific instructions below.
31
+ ## <a name="iOS"></a>iOS
21
32
 
22
- [1]: https://app.mparticle.com/apps
33
+ 1. **Copy your mParticle key and secret** from [your app's dashboard][1].
23
34
 
24
- ## <a name="iOS"></a>iOS
35
+ [1]: https://app.mparticle.com/setup/inputs/apps
25
36
 
26
- **Install the SDK** using CocoaPods:
37
+ 2. **Install the SDK** using CocoaPods:
27
38
 
28
39
  ```bash
29
40
  $ # Update your Podfile to depend on 'mParticle-Apple-SDK' version 7.2.0 or later
30
41
  $ pod install
31
42
  ```
32
43
 
33
- The mParticle SDK is initialized by calling the `startWithOptions` method within the `application:didFinishLaunchingWithOptions:` delegate call. Preferably the location of the initialization method call should be one of the last statements in the `application:didFinishLaunchingWithOptions:`. The `startWithOptions` method requires an options argument containing your key and secret and an initial Identity request.
44
+ The mParticle SDK is initialized by calling the `startWithOptions` method within the `application:didFinishLaunchingWithOptions:` delegate call.
45
+
46
+ Preferably the location of the initialization method call should be one of the last statements in the `application:didFinishLaunchingWithOptions:`.
47
+
48
+ The `startWithOptions` method requires an options argument containing your key and secret and an initial Identity request.
49
+
50
+ > Note that you must initialize the SDK in the `application:didFinishLaunchingWithOptions:` method. Other parts of the SDK rely on the `UIApplicationDidBecomeActiveNotification` notification to function properly. Failing to start the SDK as indicated will impair it. Also, please do **not** use _GCD_'s `dispatch_async` to start the SDK.
34
51
 
35
- > Note that it is imperative for the SDK to be initialized in the `application:didFinishLaunchingWithOptions:` method. Other parts of the SDK rely on the `UIApplicationDidBecomeActiveNotification` notification to function properly. Failing to start the SDK as indicated will impair it. Also, please do **not** use _GCD_'s `dispatch_async` to start the SDK.
52
+ For more help, see [the iOS set up docs](https://docs.mparticle.com/developers/sdk/ios/getting-started/#create-an-input).
36
53
 
37
- #### Swift
54
+ 3. Import and start the mParticle Apple SDK into Swift or Objective-C.
55
+
56
+
57
+ #### Swift Example
38
58
 
39
59
  ```swift
40
60
  import mParticle_Apple_SDK
@@ -62,7 +82,7 @@ func application(_ application: UIApplication, didFinishLaunchingWithOptions lau
62
82
  }
63
83
  ```
64
84
 
65
- #### Objective-C
85
+ #### Objective-C Example
66
86
 
67
87
  For apps supporting iOS 8 and above, Apple recommends using the import syntax for **modules** or **semantic import**. However, if you prefer the traditional CocoaPods and static libraries delivery mechanism, that is fully supported as well.
68
88
 
@@ -107,15 +127,17 @@ Next, you'll need to start the SDK:
107
127
  }
108
128
  ```
109
129
 
110
- Please see [Identity](http://docs.mparticle.com/developers/sdk/ios/identity/) for more information on supplying an `MPIdentityApiRequest` object during SDK initialization.
130
+ See [Identity](http://docs.mparticle.com/developers/sdk/ios/identity/) for more information on supplying an `MPIdentityApiRequest` object during SDK initialization.
111
131
 
112
132
 
113
133
  ## <a name="Android"></a>Android
114
134
 
115
- 1. Grab your mParticle key and secret from [your workspace's dashboard](https://app.mparticle.com/apps) and construct an `MParticleOptions` object.
135
+ 1. Copy your mParticle key and secret from [your workspace's dashboard](https://app.mparticle.com/setup/inputs/apps) and construct an `MParticleOptions` object.
116
136
 
117
137
  2. Call `start` from the `onCreate` method of your app's `Application` class. It's crucial that the SDK be started here for proper session management. If you don't already have an `Application` class, create it and then specify its fully-qualified name in the `<application>` tag of your app's `AndroidManifest.xml`.
118
138
 
139
+ For more help, see [the Android set up docs](https://docs.mparticle.com/developers/sdk/android/getting-started/#create-an-input).
140
+
119
141
  ```java
120
142
  package com.example.myapp;
121
143
 
@@ -143,28 +165,26 @@ public class MyApplication extends Application {
143
165
  }
144
166
  ```
145
167
 
146
- > **Warning:** It's generally not a good idea to log events in your `Application.onCreate()`. Android may instantiate your `Application` class for a lot of reasons, in the background, while the user isn't even using their device.
168
+ > **Warning:** Don't log events in your `Application.onCreate()`. Android may instantiate your `Application` class in the background without your knowledge, including when the user isn't using their device, and lead to unexpected results.
147
169
 
148
170
 
149
171
  # Usage
150
172
 
151
- ## Import
152
-
153
- **Importing** the module:
173
+ ## Import the mParticle Module
154
174
 
155
175
  ```js
156
176
  import MParticle from 'react-native-mparticle'
157
177
  ```
158
178
 
159
- ## Events
179
+ ## Logging Events
160
180
 
161
- **Logging** events:
181
+ To log basic events:
162
182
 
163
183
  ```js
164
184
  MParticle.logEvent('Test event', MParticle.EventType.Other, { 'Test key': 'Test value' })
165
185
  ```
166
186
 
167
- **Logging** commerce events:
187
+ To log commerce events:
168
188
 
169
189
  ```js
170
190
  const product = new MParticle.Product('Test product for cart', '1234', 19.99)
@@ -189,16 +209,16 @@ const event = MParticle.CommerceEvent.createImpressionEvent([impression])
189
209
  MParticle.logCommerceEvent(event)
190
210
  ```
191
211
 
192
- **Logging** screen events:
212
+ To log screen events:
193
213
 
194
214
  ```js
195
215
  MParticle.logScreenEvent('Test screen', { 'Test key': 'Test value' })
196
216
  ```
197
217
 
198
218
  ## User
199
- **Setting** user attributes and tags:
200
219
 
201
- Use Identify or currentUser to retrieve the userID for these calls
220
+ To set, remove, and get user details, call the `User` or `Identity` methods as follows:
221
+
202
222
  ```js
203
223
  MParticle.User.setUserAttribute('User ID', 'Test key', 'Test value')
204
224
  ```
@@ -254,9 +274,6 @@ MParticle.Identity.getCurrentUser((currentUser) => {
254
274
  });
255
275
  ```
256
276
 
257
- **Using** static methods to update and change identity
258
-
259
-
260
277
  ```js
261
278
  var request = new MParticle.IdentityRequest();
262
279
 
@@ -330,7 +347,7 @@ MParticle.setOptOut(!isOptedOut);
330
347
 
331
348
  ## Push Registration
332
349
 
333
- The method `MParticle.logPushRegistration()` accepts 2 parameters. For Android, provide both the pushToken and senderId. For iOS, provide the push token in the first parameter, and simply pass `null` for the second parameter
350
+ The method `MParticle.logPushRegistration()` accepts 2 parameters. For Android, provide both the `pushToken` and `senderId`. For iOS, provide the push token in the first parameter, and simply pass `null` for the second parameter.
334
351
 
335
352
  ### Android
336
353
 
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <classpath>
3
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
4
+ <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
5
+ <classpathentry kind="output" path="bin/default"/>
6
+ </classpath>
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>android</name>
4
+ <comment>Project android created by Buildship.</comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.eclipse.jdt.core.javabuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ <buildCommand>
14
+ <name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15
+ <arguments>
16
+ </arguments>
17
+ </buildCommand>
18
+ </buildSpec>
19
+ <natures>
20
+ <nature>org.eclipse.jdt.core.javanature</nature>
21
+ <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22
+ </natures>
23
+ <filteredResources>
24
+ <filter>
25
+ <id>1630678802180</id>
26
+ <name></name>
27
+ <type>30</type>
28
+ <matcher>
29
+ <id>org.eclipse.core.resources.regexFilterMatcher</id>
30
+ <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
31
+ </matcher>
32
+ </filter>
33
+ </filteredResources>
34
+ </projectDescription>
@@ -0,0 +1,13 @@
1
+ arguments=
2
+ auto.sync=false
3
+ build.scans.enabled=false
4
+ connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
5
+ connection.project.dir=
6
+ eclipse.preferences.version=1
7
+ gradle.user.home=
8
+ java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
9
+ jvm.arguments=
10
+ offline.mode=false
11
+ override.workspace.settings=true
12
+ show.console.view=true
13
+ show.executions.view=true
@@ -24,7 +24,7 @@ android {
24
24
 
25
25
  buildscript {
26
26
  repositories {
27
- jcenter()
27
+ mavenCentral()
28
28
  google()
29
29
  }
30
30
  dependencies {
@@ -33,7 +33,7 @@ buildscript {
33
33
  }
34
34
 
35
35
  repositories {
36
- jcenter()
36
+ mavenCentral()
37
37
  google()
38
38
  }
39
39
 
@@ -508,6 +508,10 @@ public class MParticleModule extends ReactContextBaseJavaModule {
508
508
  }
509
509
  }
510
510
 
511
+ if (map.hasKey("shouldUploadEvent")) {
512
+ builder.shouldUploadEvent(map.getBoolean("shouldUploadEvent"));
513
+ }
514
+
511
515
  return builder.build();
512
516
  }
513
517
 
@@ -588,6 +592,13 @@ public class MParticleModule extends ReactContextBaseJavaModule {
588
592
  }
589
593
  }
590
594
 
595
+ if (map.hasKey("shouldUploadEvent")) {
596
+ builder.shouldUploadEvent(map.getBoolean("shouldUploadEvent"));
597
+ }
598
+ if (map.hasKey("customAttributes")) {
599
+ builder.customAttributes(ConvertStringMap(map.getMap("customAttributes")));
600
+ }
601
+
591
602
  return builder.build();
592
603
  }
593
604
 
@@ -708,7 +719,34 @@ public class MParticleModule extends ReactContextBaseJavaModule {
708
719
  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
709
720
  while (iterator.hasNextKey()) {
710
721
  String key = iterator.nextKey();
711
- map.put(key, readableMap.getString(key));
722
+ switch (readableMap.getType(key)) {
723
+ case Null:
724
+ map.put(key, null);
725
+ break;
726
+ case Boolean:
727
+ map.put(key, Boolean.valueOf(readableMap.getBoolean(key)).toString());
728
+ break;
729
+ case Number:
730
+ try {
731
+ map.put(key, Integer.toString(readableMap.getInt(key)));
732
+ } catch (Exception e) {
733
+ try {
734
+ map.put(key, Double.toString(readableMap.getDouble(key)));
735
+ } catch (Exception ex) {
736
+ Logger.warning("Unable to parse value for \"" + key + "\"");
737
+ }
738
+ }
739
+ break;
740
+ case String:
741
+ map.put(key, readableMap.getString(key));
742
+ break;
743
+ case Map:
744
+ Logger.warning("Maps are not supported Attribute value types");
745
+ break;
746
+ case Array:
747
+ Logger.warning("Lists are not supported Attribute value types");
748
+ break;
749
+ }
712
750
  }
713
751
  }
714
752
 
@@ -413,9 +413,14 @@ typedef NS_ENUM(NSUInteger, MPReactCommerceEventAction) {
413
413
  commerceEvent.productListSource = json[@"productActionListSource"];
414
414
  commerceEvent.screenName = json[@"screenName"];
415
415
  commerceEvent.transactionAttributes = [RCTConvert MPTransactionAttributes:json[@"transactionAttributes"]];
416
- commerceEvent.action = [RCTConvert MPCommerceEventAction:json[@"productActionType"]];
417
416
  commerceEvent.checkoutStep = [json[@"checkoutStep"] intValue];
418
417
  commerceEvent.nonInteractive = [json[@"nonInteractive"] boolValue];
418
+ if (json[@"shouldUploadEvent"] != nil) {
419
+ commerceEvent.shouldUploadEvent = [json[@"shouldUploadEvent"] boolValue];
420
+ }
421
+ if (json[@"customAttributes"] != nil) {
422
+ commerceEvent.customAttributes = json[@"customAttributes"];
423
+ }
419
424
 
420
425
  NSMutableArray *products = [NSMutableArray array];
421
426
  NSArray *jsonProducts = json[@"products"];
@@ -602,6 +607,9 @@ typedef NS_ENUM(NSUInteger, MPReactCommerceEventAction) {
602
607
  event.name = json[@"name"];
603
608
  event.startTime = json[@"startTime"];
604
609
  event.type = [json[@"type"] intValue];
610
+ if (json[@"shouldUploadEvent"] != nil) {
611
+ event.shouldUploadEvent = [json[@"shouldUploadEvent"] boolValue];
612
+ }
605
613
 
606
614
  NSDictionary *jsonFlags = json[@"customFlags"];
607
615
  for (NSString *key in jsonFlags) {
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Bucket
3
+ uuid = "39402CF6-7BAB-4033-9C4A-41AE5477C134"
4
+ type = "1"
5
+ version = "2.0">
6
+ </Bucket>
package/js/index.js CHANGED
@@ -161,7 +161,7 @@ class User {
161
161
 
162
162
  setUserAttribute (key, value) {
163
163
  if (value && value.constructor === Array) {
164
- NativeModules.Mparticle.setUserAttributeArray(this.userId, key, value)
164
+ NativeModules.MParticle.setUserAttributeArray(this.userId, key, value)
165
165
  } else {
166
166
  NativeModules.MParticle.setUserAttribute(this.userId, key, value)
167
167
  }
@@ -172,7 +172,7 @@ class User {
172
172
  }
173
173
 
174
174
  getUserAttributes (completion) {
175
- NativeModules.MParticle.getUserAttributes((error, userAttributes) => {
175
+ NativeModules.MParticle.getUserAttributes(this.userId, (error, userAttributes) => {
176
176
  if (error) {
177
177
  console.log(error.stack)
178
178
  }
@@ -566,6 +566,11 @@ class CommerceEvent {
566
566
  this.nonInteractive = nonInteractive
567
567
  return this
568
568
  }
569
+
570
+ setShouldUploadEvent (shouldUploadEvent) {
571
+ this.shouldUploadEvent = shouldUploadEvent
572
+ return this
573
+ }
569
574
  }
570
575
 
571
576
  class Event {
@@ -605,6 +610,11 @@ class Event {
605
610
  return this
606
611
  }
607
612
 
613
+ setShouldUploadEvent (shouldUploadEvent) {
614
+ this.shouldUploadEvent = shouldUploadEvent
615
+ return this
616
+ }
617
+
608
618
  setCustomFlags (customFlags) {
609
619
  this.customFlags = customFlags
610
620
  return this
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "homepage": "https://www.mparticle.com",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "mParticle/react-native-mparticle",
7
- "version": "2.4.12",
7
+ "version": "2.6.1",
8
8
  "main": "js/index.js",
9
9
  "scripts": {
10
10
  "test": "./node_modules/standard/bin/cmd.js",
package/release.sh ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ : ${1?"NPM Token missing- usage: $0 {MY_NPM_TOKEN}"}
3
+
4
+ touch .npmrc;
5
+ echo "//registry.npmjs.org/:_authToken=$1" > .npmrc;
6
+ npm publish;