react-native-google-analytics-bridge
Advanced tools
Comparing version 1.2.0 to 1.3.0
39
index.js
@@ -5,2 +5,11 @@ "use strict"; | ||
let _trackerId = GoogleAnalyticsBridge.nativeTrackerId; | ||
const getTrackerId = () => { | ||
if (!_trackerId) { | ||
throw new Error("TrackerId not set. See documentation for more details"); | ||
} | ||
return _trackerId | ||
} | ||
class GoogleAnalytics { | ||
@@ -12,3 +21,3 @@ /** | ||
static trackScreenView(screenName) { | ||
GoogleAnalyticsBridge.trackScreenView(screenName); | ||
GoogleAnalyticsBridge.trackScreenView(getTrackerId(), screenName); | ||
} | ||
@@ -23,3 +32,3 @@ | ||
static trackEvent(category, action, optionalValues = {}) { | ||
GoogleAnalyticsBridge.trackEvent(category, action, optionalValues); | ||
GoogleAnalyticsBridge.trackEvent(getTrackerId(), category, action, optionalValues); | ||
} | ||
@@ -34,3 +43,3 @@ | ||
static trackTiming(category, value, optionalValues = {}) { | ||
GoogleAnalyticsBridge.trackTiming(category, value, optionalValues); | ||
GoogleAnalyticsBridge.trackTiming(getTrackerId(), category, value, optionalValues); | ||
} | ||
@@ -46,3 +55,3 @@ | ||
static trackPurchaseEvent(product = {}, transaction = {}, eventCategory = "Ecommerce", eventAction = "Purchase") { | ||
GoogleAnalyticsBridge.trackPurchaseEvent(product, transaction, eventCategory, eventAction); | ||
GoogleAnalyticsBridge.trackPurchaseEvent(getTrackerId(), product, transaction, eventCategory, eventAction); | ||
} | ||
@@ -56,3 +65,3 @@ | ||
static trackException(error, fatal = false) { | ||
GoogleAnalyticsBridge.trackException(error, fatal); | ||
GoogleAnalyticsBridge.trackException(getTrackerId(), error, fatal); | ||
} | ||
@@ -65,3 +74,3 @@ | ||
static setUser(userId) { | ||
GoogleAnalyticsBridge.setUser(userId); | ||
GoogleAnalyticsBridge.setUser(getTrackerId(), userId); | ||
} | ||
@@ -74,3 +83,3 @@ | ||
static allowIDFA(enabled = true) { | ||
GoogleAnalyticsBridge.allowIDFA(enabled); | ||
GoogleAnalyticsBridge.allowIDFA(getTrackerId(), enabled); | ||
} | ||
@@ -85,3 +94,3 @@ | ||
static trackSocialInteraction(network, action, targetUrl) { | ||
GoogleAnalyticsBridge.trackSocialInteraction(network, action, targetUrl); | ||
GoogleAnalyticsBridge.trackSocialInteraction(getTrackerId(), network, action, targetUrl); | ||
} | ||
@@ -113,3 +122,3 @@ | ||
static setTrackUncaughtExceptions(enabled) { | ||
GoogleAnalyticsBridge.setTrackUncaughtExceptions(enabled); | ||
GoogleAnalyticsBridge.setTrackUncaughtExceptions(getTrackerId(), enabled); | ||
} | ||
@@ -119,7 +128,7 @@ | ||
* Sets if AnonymizeIp is enabled | ||
* If enabled the last octet of the IP address will be removed | ||
* If enabled the last octet of the IP address will be removed | ||
* @param {Boolean} enabled | ||
*/ | ||
static setAnonymizeIp(enabled) { | ||
GoogleAnalyticsBridge.setAnonymizeIp(enabled); | ||
GoogleAnalyticsBridge.setAnonymizeIp(getTrackerId(), enabled); | ||
} | ||
@@ -136,4 +145,12 @@ | ||
/** | ||
* Sets new tracker ID for all subsequent static calls | ||
* @param {String} tracker ID | ||
*/ | ||
static setTrackerId(trackerId) { | ||
_trackerId = trackerId; | ||
} | ||
} | ||
module.exports = GoogleAnalytics; |
{ | ||
"name": "react-native-google-analytics-bridge", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "React Native bridge for using native Google Analytics libraries on iOS and Android", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -11,2 +11,3 @@ GoogleAnalyticsBridge ![npm version](https://img.shields.io/npm/v/react-native-google-analytics-bridge.svg) | ||
const GoogleAnalytics = require('react-native-google-analytics-bridge'); | ||
GoogleAnalytics.setTrackerId('UA-12345-1'); | ||
@@ -21,6 +22,4 @@ GoogleAnalytics.trackScreenView('Home'); | ||
With this, [rnpm](https://github.com/rnpm/rnpm) will do most of the heavy lifting for linking, **but** you will still need to do some of the manual steps below. | ||
With this, [rnpm](https://github.com/rnpm/rnpm) will do most of the heavy lifting for linking, **but** for iOS you will still need to do step 5 from the manual installation guide below. | ||
These are step 5 and 6 from the iOS installation, and step 4 from the Android installation. Specifically for Android step 4, you'll have to add the tracking id. | ||
## Manual installation iOS | ||
@@ -37,7 +36,3 @@ | ||
4. libsqlite3.0.tbd | ||
6. Under your project properties ➜ "Info", add a new line with the following: | ||
1. Key: GAITrackingId | ||
2. Type: String | ||
3. Value: UA-12345-1 (in other words, your own tracking id). | ||
7. **Optional step**: If you plan on using the advertising identifier (IDFA), then you need to do two things: | ||
6. **Optional step**: If you plan on using the advertising identifier (IDFA), then you need to do two things: | ||
1. Add AdSupport.framework under "Link Binary With Libraries". (As with the other frameworks in step 5). | ||
@@ -61,4 +56,4 @@ 2. Go to Xcode ➜ `Libraries` ➜ `RCTGoogleAnalyticsBridge.xcodeproj` ➜ right-click `google-analytics-lib`. Here you need to `Add files to ..`, and add `libAdIdAccess.a` from the `google-analytics-lib` directory. This directory is located in the same `node_modules` path as in step 3. | ||
... | ||
include ':GoogleAnalyticsBridge', ':app' | ||
project(':GoogleAnalyticsBridge').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-analytics-bridge/android') | ||
include ':react-native-google-analytics-bridge', ':app' | ||
project(':react-native-google-analytics-bridge').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-analytics-bridge/android') | ||
``` | ||
@@ -72,3 +67,3 @@ | ||
... | ||
compile project(':GoogleAnalyticsBridge') | ||
compile project(':react-native-google-analytics-bridge') | ||
} | ||
@@ -95,4 +90,4 @@ ``` | ||
.addPackage(new MainReactPackage()) | ||
// Step 2; register package, with your GA tracking id: | ||
.addPackage(new GoogleAnalyticsBridgePackage("UA-12345-1")) | ||
// Step 2; register package: | ||
.addPackage(new GoogleAnalyticsBridgePackage()) | ||
.setUseDeveloperSupport(BuildConfig.DEBUG) | ||
@@ -109,2 +104,12 @@ .setInitialLifecycleState(LifecycleState.RESUMED) | ||
### setTrackerId(trackerId) | ||
* **trackerId (required):** String, your tracker id, something like: UA-12345-1 | ||
**Important**: Call **once** on app startup to set the tracker id for all subsequent static calls. | ||
```javascript | ||
const GoogleAnalytics = require('react-native-google-analytics-bridge'); | ||
GoogleAnalytics.setTrackerId('UA-12345-1') | ||
``` | ||
### trackScreenView(screenName) | ||
@@ -238,4 +243,6 @@ | ||
**Important**: For iOS you can only use this method if you have done the optional step 7 from the installation guide. | ||
Also called advertising identifier collection, and is used for advertising features. | ||
**Important**: For iOS you can only use this method if you have done the optional step 6 from the installation guide. Only enable this (and link the appropriate libraries) if you plan to use advertising features in your app, or else your app may get rejected from the AppStore. | ||
See the [Google Analytics](https://developers.google.com/analytics/devguides/collection/ios/v3/campaigns#ios-install) for more info. | ||
@@ -316,2 +323,3 @@ | ||
- [ ] Support for A/B testing | ||
- [ ] Ecommerce: checkout process | ||
@@ -327,2 +335,2 @@ - [ ] Ecommerce: impressions | ||
I've decided to remove the React Native peerDependency since some users have had issues with how npm handles peerDependencies, especially with -rc versions. | ||
I've decided to remove the React Native peerDependency since some users have had issues with how npm handles peerDependencies, especially with -rc versions. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
34400724
356
326