react-native-google-analytics-bridge
Advanced tools
Comparing version 3.1.0 to 4.0.0
255
index.js
@@ -1,241 +0,18 @@ | ||
"use strict"; | ||
import { GoogleAnalyticsBackwardsCompability } from './src/GoogleAnalyticsBackwardsCompability'; | ||
import { GoogleAnalyticsTracker } from './src/GoogleAnalyticsTracker'; | ||
import { GoogleAnalyticsSettings } from './src/GoogleAnalyticsSettings'; | ||
import { GoogleTagManager } from './src/GoogleTagManager'; | ||
import { GoogleAnalyticsBridge } from './src/NativeBridges'; | ||
const GoogleAnalyticsBridge = require("react-native").NativeModules.GoogleAnalyticsBridge; | ||
const GoogleTagManagerBridge = require("react-native").NativeModules.GoogleTagManagerBridge; | ||
export { | ||
GoogleAnalyticsTracker, | ||
GoogleAnalyticsSettings, | ||
GoogleTagManager, | ||
}; | ||
let _trackerId = GoogleAnalyticsBridge.nativeTrackerId; | ||
const getTrackerId = () => { | ||
if (!_trackerId) { | ||
throw new Error("TrackerId not set. See documentation for more details"); | ||
} | ||
return _trackerId | ||
} | ||
class GoogleAnalytics { | ||
/** | ||
* Track the current screen/view | ||
* @param {String} screenName The name of the current screen | ||
*/ | ||
static trackScreenView(screenName) { | ||
GoogleAnalyticsBridge.trackScreenView(getTrackerId(), screenName); | ||
} | ||
/** | ||
* Track an event that has occured | ||
* @param {String} category The event category | ||
* @param {String} action The event action | ||
* @param {Object} optionalValues An object containing optional label and value | ||
*/ | ||
static trackEvent(category, action, optionalValues = {}) { | ||
GoogleAnalyticsBridge.trackEvent(getTrackerId(), category, action, optionalValues); | ||
} | ||
/** | ||
* Track the current screen/view with custom dimension values | ||
* @param {String} screenName The name of the current screen | ||
* @param {Object} customDimensionValues An object containing custom dimension key/value pairs | ||
*/ | ||
static trackScreenViewWithCustomDimensionValues(screenName, customDimensionValues) { | ||
GoogleAnalyticsBridge.trackScreenViewWithCustomDimensionValues(getTrackerId(), screenName, customDimensionValues); | ||
} | ||
/** | ||
* Track an event that has occured with custom dimension values | ||
* @param {String} category The event category | ||
* @param {String} action The event action | ||
* @param {Object} optionalValues An object containing optional label and value | ||
* @param {Object} customDimensionValues An object containing custom dimension key/value pairs | ||
*/ | ||
static trackEventWithCustomDimensionValues(category, action, optionalValues = {}, customDimensionValues) { | ||
GoogleAnalyticsBridge.trackEventWithCustomDimensionValues(getTrackerId(), category, action, optionalValues, customDimensionValues); | ||
} | ||
/** | ||
* Track an event that has occured | ||
* @param {String} category The event category | ||
* @param {Number} value The timing measurement in milliseconds | ||
* @param {Object} optionalValues An object containing optional name and label | ||
*/ | ||
static trackTiming(category, value, optionalValues = {}) { | ||
GoogleAnalyticsBridge.trackTiming(getTrackerId(), category, value, optionalValues); | ||
} | ||
/** | ||
* Track a purchase event. This uses the Enhanced Ecommerce GA feature. | ||
* @param {Object} product An object with product values | ||
* @param {Object} transaction An object with transaction values | ||
* @param {String} eventCategory The event category, defaults to Ecommerce | ||
* @param {String} eventAction The event action, defaults to Purchase | ||
*/ | ||
static trackPurchaseEvent(product = {}, transaction = {}, eventCategory = "Ecommerce", eventAction = "Purchase") { | ||
GoogleAnalyticsBridge.trackPurchaseEvent(getTrackerId(), product, transaction, eventCategory, eventAction); | ||
} | ||
/** | ||
* Track a purchase event. This uses the Enhanced Ecommerce GA feature. | ||
* @param {Array} products An array with products | ||
* @param {Object} transaction An object with transaction values | ||
* @param {String} eventCategory The event category, defaults to Ecommerce | ||
* @param {String} eventAction The event action, defaults to Purchase | ||
*/ | ||
static trackMultiProductsPurchaseEvent(products = [], transaction = {}, eventCategory = "Ecommerce", eventAction = "Purchase") { | ||
GoogleAnalyticsBridge.trackMultiProductsPurchaseEvent(getTrackerId(), products, transaction, eventCategory, eventAction); | ||
} | ||
/** | ||
* Track an exception | ||
* @param {String} error The description of the error | ||
* @param {Boolean} fatal A value indiciating if the error was fatal, defaults to false | ||
*/ | ||
static trackException(error, fatal = false) { | ||
GoogleAnalyticsBridge.trackException(getTrackerId(), error, fatal); | ||
} | ||
/** | ||
* Sets the current userId for tracking. | ||
* @param {String} userId The current userId | ||
*/ | ||
static setUser(userId) { | ||
GoogleAnalyticsBridge.setUser(getTrackerId(), userId); | ||
} | ||
/** | ||
* Sets if IDFA (identifier for advertisers) collection should be enabled | ||
* @param {Boolean} enabled Defaults to true | ||
*/ | ||
static allowIDFA(enabled = true) { | ||
GoogleAnalyticsBridge.allowIDFA(getTrackerId(), enabled); | ||
} | ||
/** | ||
* Track a social interaction, Facebook, Twitter, etc. | ||
* @param {String} network | ||
* @param {String} action | ||
* @param {String} targetUrl | ||
*/ | ||
static trackSocialInteraction(network, action, targetUrl) { | ||
GoogleAnalyticsBridge.trackSocialInteraction(getTrackerId(), network, action, targetUrl); | ||
} | ||
/** | ||
* Sets if the tracker should have dry run enabled. | ||
* If dry run is enabled, no analytics data will be sent to your tracker. | ||
* @param {Boolean} enabled | ||
*/ | ||
static setDryRun(enabled) { | ||
GoogleAnalyticsBridge.setDryRun(enabled); | ||
} | ||
/** | ||
* Sets the trackers dispatch interval | ||
* This will influence how often batches of events, screen views, etc | ||
* are sent to your tracker. | ||
* @param {Number} intervalInSeconds | ||
*/ | ||
static setDispatchInterval(intervalInSeconds) { | ||
GoogleAnalyticsBridge.setDispatchInterval(intervalInSeconds); | ||
} | ||
/** | ||
* Sets if uncaught exceptions should be tracked | ||
* @param {Boolean} enabled | ||
*/ | ||
static setTrackUncaughtExceptions(enabled) { | ||
GoogleAnalyticsBridge.setTrackUncaughtExceptions(getTrackerId(), enabled); | ||
} | ||
/** | ||
* Sets if AnonymizeIp is enabled | ||
* If enabled the last octet of the IP address will be removed | ||
* @param {Boolean} enabled | ||
*/ | ||
static setAnonymizeIp(enabled) { | ||
GoogleAnalyticsBridge.setAnonymizeIp(getTrackerId(), enabled); | ||
} | ||
/** | ||
* Sets if OptOut is active and disables Google Analytics | ||
* This has to be set each time the App starts | ||
* @param {Boolean} enabled | ||
*/ | ||
static setOptOut(enabled) { | ||
GoogleAnalyticsBridge.setOptOut(enabled); | ||
} | ||
/** | ||
* Sets the trackers appName | ||
* The Bundle name is used by default | ||
* @param {String} appName | ||
*/ | ||
static setAppName(appName) { | ||
GoogleAnalyticsBridge.setAppName(getTrackerId(), appName); | ||
} | ||
/** | ||
* Sets new tracker ID for all subsequent static calls | ||
* @param {String} tracker ID | ||
*/ | ||
static setTrackerId(trackerId) { | ||
_trackerId = trackerId; | ||
} | ||
/** | ||
* Sets the trackers appVersion | ||
* @param {String} appVersion | ||
*/ | ||
static setAppVersion(appVersion) { | ||
GoogleAnalyticsBridge.setAppVersion(getTrackerId(), appVersion); | ||
} | ||
} | ||
class GoogleTagManager { | ||
/** | ||
* Call once to open the container for all subsequent static calls. | ||
* @param {String} containerId | ||
*/ | ||
static openContainerWithId(containerId){ | ||
return GoogleTagManagerBridge.openContainerWithId(containerId); | ||
} | ||
/** | ||
* Retrieves a boolean value with the given key from the opened container. | ||
* @param {String} key | ||
*/ | ||
static boolForKey(key){ | ||
return GoogleTagManagerBridge.booleanForKey(key); | ||
} | ||
/** | ||
* Retrieves a string with the given key from the opened container. | ||
* @param {String} key | ||
*/ | ||
static stringForKey(key){ | ||
return GoogleTagManagerBridge.stringForKey(key); | ||
} | ||
/** | ||
* Retrieves a number with the given key from the opened container. | ||
* @param {String} key | ||
*/ | ||
static doubleForKey(key){ | ||
return GoogleTagManagerBridge.doubleForKey(key); | ||
} | ||
/** | ||
* push a datalayer event for Google Analytics through Google Tag Manager. | ||
* @param {String} eventName | ||
* @param {Object} dictionaly An Map<String, Object> containing key and value pairs. | ||
it must have atleast one key "event" with event name | ||
* example: {event: "eventName", pageId: "/home"} | ||
*/ | ||
static pushDataLayerEvent(dictionaly = {}){ | ||
GoogleTagManagerBridge.pushDataLayerEvent(dictionaly); | ||
} | ||
} | ||
GoogleAnalytics.GoogleTagManager = GoogleTagManager; | ||
module.exports = GoogleAnalytics; | ||
/** | ||
* Backwards compatibility default export. | ||
* Versions bellow 3.1.0 used static GoogleAnalytics class. | ||
* This exported instance makes sure older implementations work. | ||
*/ | ||
export default new GoogleAnalyticsBackwardsCompability(GoogleAnalyticsBridge.nativeTrackerId); |
{ | ||
"name": "react-native-google-analytics-bridge", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "React Native bridge for using native Google Analytics libraries on iOS and Android", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
334
README.md
@@ -5,4 +5,2 @@ GoogleAnalyticsBridge [![npm version](https://img.shields.io/npm/v/react-native-google-analytics-bridge.svg)](https://www.npmjs.com/package/react-native-google-analytics-bridge) [![Build Status](https://travis-ci.org/idehub/react-native-google-analytics-bridge.svg?branch=master)](https://travis-ci.org/idehub/react-native-google-analytics-bridge) | ||
**Important**: This library requires React Native v0.19+. | ||
## Why a native bridge? Why not use just JavaScript? | ||
@@ -13,31 +11,33 @@ The key difference with the native bridge is that you get a lot of the metadata handled automatically by the Google Analytics native library. This will include the device UUID, device model, viewport size, OS version etc. | ||
```javascript | ||
import GoogleAnalytics from 'react-native-google-analytics-bridge'; | ||
GoogleAnalytics.setTrackerId('UA-12345-1'); | ||
import { GoogleAnalyticsTracker } from 'react-native-google-analytics-bridge'; | ||
let tracker = new GoogleAnalyticsTracker('UA-12345-1'); | ||
GoogleAnalytics.trackScreenView('Home'); | ||
GoogleAnalytics.trackEvent('testcategory', 'testaction'); | ||
tracker.trackScreenView('Home'); | ||
tracker.trackEvent('testcategory', 'testaction'); | ||
``` | ||
## Installation with rnpm | ||
`rnpm install react-native-google-analytics-bridge` | ||
## Content | ||
* [Installation](#installation-and-linking-libraries) | ||
* [Manual installation](https://github.com/idehub/react-native-google-analytics-bridge/wiki/Manual-installation) | ||
* [Usage](#usage) | ||
* [JavaScript API](#javascript-api) | ||
* [Troubleshooting](https://github.com/idehub/react-native-google-analytics-bridge/wiki/Troubleshooting) | ||
* [A/B testing](https://github.com/idehub/react-native-google-analytics-bridge/wiki/Simple-A-B-testing) | ||
* [Roadmap](https://github.com/idehub/react-native-google-analytics-bridge/wiki/Roadmap) | ||
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. | ||
## Installation and linking libraries | ||
## Manual installation iOS | ||
Install with npm: `npm install --save react-native-google-analytics-bridge`. | ||
1. `npm install --save react-native-google-analytics-bridge` | ||
2. In XCode, right-click the Libraries folder under your project ➜ `Add Files to <your project>`. | ||
3. Go to `node_modules` ➜ `react-native-google-analytics-bridge` ➜ `ios` ➜ `RCTGoogleAnalyticsBridge` and add the `RCTGoogleAnalyticsBridge.xcodeproj` file. | ||
4. Add libRCTGoogleAnalyticsBridge.a from the linked project to your project properties ➜ "Build Phases" ➜ "Link Binary With Libraries" | ||
5. Next you will have to link a few more SDK framework/libraries which are required by GA (if you do not already have them linked.) Under the same "Link Binary With Libraries", click the + and add the following: | ||
1. CoreData.framework | ||
2. SystemConfiguration.framework | ||
3. libz.tbd | ||
4. libsqlite3.0.tbd | ||
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). | ||
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. | ||
Or, install with yarn: `yarn add react-native-google-analytics-bridge`. | ||
## Prerequisites for Android | ||
Make sure you have the following SDK packages installed in the Android SDK Manager: | ||
Either way, then link with `react-native link react-native-google-analytics-bridge`. | ||
For iOS you must also link a few more SDK packages in Xcode, which are required by GA: | ||
* CoreData.framework | ||
* SystemConfiguration.framework | ||
* libz.tbd | ||
* libsqlite3.0.tbd | ||
For Android, make sure you have the following SDK packages installed in the Android SDK Manager: | ||
* Google Repository | ||
@@ -47,73 +47,64 @@ * Google Play services | ||
Consult [this guide](https://developer.android.com/studio/intro/update.html#sdk-manager) if you are unsure how to do this. | ||
For more details about the native SDKs, consult the [manual installation guide](https://github.com/idehub/react-native-google-analytics-bridge/wiki/Manual-installation). | ||
## Manual installation Android | ||
## Usage | ||
```javascript | ||
// You have access to three classes in this module: | ||
import { | ||
GoogleAnalyticsTracker, | ||
GoogleTagManager, | ||
GoogleAnalyticsSettings | ||
} from 'react-native-google-analytics-bridge'; | ||
1. `npm install --save react-native-google-analytics-bridge` | ||
2. Add the following in `android/settings.gradle` | ||
// The tracker must be constructed, and you can have multiple: | ||
let tracker1 = new GoogleAnalyticsTracker('UA-12345-1'); | ||
let tracker2 = new GoogleAnalyticsTracker('UA-12345-2'); | ||
```gradle | ||
... | ||
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') | ||
``` | ||
tracker1.trackScreenView('Home'); | ||
tracker1.trackEvent('Customer', 'New'); | ||
3. And the following in `android/app/build.gradle` | ||
// The GoogleAnalyticsSettings is static, and settings are applied across all trackers: | ||
GoogleAnalyticsSettings.setDispatchInterval(30); | ||
GoogleAnalyticsSettings.setDryRun(true); | ||
```gradle | ||
... | ||
dependencies { | ||
... | ||
compile project(':react-native-google-analytics-bridge') | ||
} | ||
``` | ||
// GoogleTagManager is also static, and works only with one container. All functions here are Promises: | ||
GoogleTagManager.openContainerWithId("GT-NZT48") | ||
.then(() => { | ||
return GoogleTagManager.stringForKey("pack"); | ||
}) | ||
.then((pack) => { | ||
console.log("Pack: ", pack); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
``` | ||
4. Register package in `MainApplication.java` | ||
## JavaScript API | ||
* [GoogleAnalyticsTracker](#googleanalyticstracker-api) | ||
* [GoogleAnalyticsSettings](#googleanalyticssettings-api) | ||
* [GoogleTagManager](#googletagmanager-api) | ||
```java | ||
// Step 1; import package: | ||
import com.idehub.GoogleAnalyticsBridge.GoogleAnalyticsBridgePackage; | ||
## GoogleAnalyticsTracker API | ||
public class MainActivity extends ReactActivity { | ||
... | ||
### new GoogleAnalyticsTracker(trackerId, customDimensionsFieldsIndexMap = {}) | ||
* **trackerId (required):** String, your tracker id, something like: UA-12345-1 | ||
* **customDimensionsFieldsIndexMap (optional):** {{fieldName: fieldIndex}} Custom dimensions field/index pairs | ||
@Override | ||
protected List<ReactPackage> getPackages() { | ||
return Arrays.<ReactPackage>asList( | ||
new MainReactPackage(), | ||
// Step 2; register package: | ||
new GoogleAnalyticsBridgePackage() | ||
); | ||
} | ||
} | ||
``` | ||
### Android build problem | ||
Some people have had problems being hit with `Unknown source file : com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzmu;` after installing this (or similar modules). | ||
This might be because you are using another module which also uses `play-services`, but targets a different version of `play-services`. In the `build.gradle`-file of this module, we target `com.google.android.gms:play-services-analytics:8.+`. In other words, we try to use the latest (8.x.x) version of `play-services`. | ||
If some other module is targetting a previous version, say 8.3.0, then adding the following to your (React Native-project) `build.gradle` may be helpful: | ||
```gradle | ||
compile("com.google.android.gms:play-services-analytics:8.3.0"){ | ||
force = true | ||
} | ||
```javascript | ||
import { GoogleAnalyticsTracker } from 'react-native-google-analytics-bridge'; | ||
let tracker = new GoogleAnalyticsTracker('UA-12345-1'); | ||
``` | ||
That should force the app to compile the 8.3.0 version of the dependency my module uses. Obviously, this might not be a solution if several modules are depending on conflicting versions. | ||
Google Analytics expects dimensions to be tracked by indices, and not field names. | ||
To simplify this, you can construct a tracker with a customDimensionsFieldsIndexMap. With this, you can map field names to indices, e.g: | ||
I would recommend other module authors which also depend on `play-services` to target `8.+` instead of a specific minor version. | ||
## Google Analytics Javascript API | ||
### 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 | ||
import GoogleAnalytics from 'react-native-google-analytics-bridge'; | ||
GoogleAnalytics.setTrackerId('UA-12345-1') | ||
let tracker2 = new GoogleAnalyticsTracker('UA-12345-3', { test: 1 }); | ||
tracker2.trackScreenViewWithCustomDimensionValues('Home', { test: 'Beta' }); | ||
``` | ||
Here the underlying logic will transform the custom dimension, so what ends up being sent to GA is `{ 1: 'Beta' }`. | ||
This should make it easier to use custom dimensions. If you do not provide a customDimensionsFieldsIndexMap, the custom dimensions are passed through untouched. | ||
### trackScreenView(screenName) | ||
@@ -128,3 +119,3 @@ | ||
```javascript | ||
GoogleAnalytics.trackScreenView('Home') | ||
tracker.trackScreenView('Home') | ||
``` | ||
@@ -143,5 +134,5 @@ | ||
```javascript | ||
GoogleAnalytics.trackEvent('testcategory', 'testaction'); | ||
tracker.trackEvent('testcategory', 'testaction'); | ||
// or | ||
GoogleAnalytics.trackEvent('testcategory', 'testaction', {label: 'v1.0.3', value: 22}); | ||
tracker.trackEvent('testcategory', 'testaction', {label: 'v1.0.3', value: 22}); | ||
``` | ||
@@ -154,3 +145,3 @@ | ||
* **optionalValues:** Object | ||
* **name:** String, the name of the timed event | ||
* **name (required):** String, the name of the timed event | ||
* **label:** String, the label of the timed event | ||
@@ -161,5 +152,5 @@ | ||
```javascript | ||
GoogleAnalytics.trackTiming('testcategory', 13000); | ||
tracker.trackTiming('testcategory', 13000, {name: 'LoadList'}); // name option is required | ||
// or | ||
GoogleAnalytics.trackTiming('testcategory', 13000, {name: 'loadList', label: 'v1.0.3'}); | ||
tracker.trackTiming('testcategory', 13000, {name: 'loadList', label: 'v1.0.3'}); | ||
``` | ||
@@ -191,3 +182,3 @@ | ||
```javascript | ||
GoogleAnalytics.trackPurchaseEvent({ | ||
tracker.trackPurchaseEvent({ | ||
id: 'P12345', | ||
@@ -215,2 +206,45 @@ name: 'Android Warhol T-Shirt', | ||
### trackMultiProductsPurchaseEventWithCustomDimensionValues(products, transaction, eventCategory, eventAction, dimensionIndexValueDict) | ||
* **products (required):** Array, array of products | ||
* **transaction (required):** Object, transaction object | ||
* **eventCategory (required):** String, defaults to "Ecommerce" | ||
* **eventAction (required):** String, defaults to "Purchase" | ||
* **dimensionIndexValueDict (required):** Dict of dimension index / values. | ||
```javascript | ||
tracker.trackMultiProductsPurchaseEventWithCustomDimensionValues([ | ||
{ | ||
id: 'P12345', | ||
name: 'Android Warhol T-Shirt', | ||
category: 'Apparel/T-Shirts', | ||
brand: 'Google', | ||
variant: 'Black', | ||
price: 29.20, | ||
quantity: 1, | ||
couponCode: 'APPARELSALE' | ||
}, | ||
{ | ||
id: 'P54321', | ||
name: 'IOS T-Shirt', | ||
category: 'Apparel/T-Shirts', | ||
brand: 'Apple', | ||
variant: 'Black', | ||
price: 10.10, | ||
quantity: 1, | ||
couponCode: 'APPARELSALE' | ||
}], | ||
{ | ||
id: 'T12345', | ||
affiliation: 'Store - Online', | ||
revenue: 52.5, | ||
tax: 7.86, | ||
shipping: 5.34, | ||
couponCode: 'SUMMER2013' | ||
}, | ||
'Ecommerce', | ||
'Purchase', | ||
{'1':'premium', '5':'foo'} | ||
); | ||
``` | ||
### trackException(error, fatal) | ||
@@ -227,3 +261,3 @@ | ||
} catch(error) { | ||
GoogleAnalytics.trackException(error.message, false); | ||
tracker.trackException(error.message, false); | ||
} | ||
@@ -241,3 +275,3 @@ ``` | ||
```javascript | ||
GoogleAnalytics.trackSocialInteraction('Twitter', 'Post'); | ||
tracker.trackSocialInteraction('Twitter', 'Post'); | ||
``` | ||
@@ -253,3 +287,3 @@ | ||
```javascript | ||
GoogleAnalytics.trackScreenViewWithCustomDimensionValues('Home', {'1':'premium', '5':'foo'}); | ||
tracker.trackScreenViewWithCustomDimensionValues('Home', {'1':'premium', '5':'foo'}); | ||
``` | ||
@@ -269,3 +303,3 @@ | ||
```javascript | ||
GoogleAnalytics.trackEventWithCustomDimensionValues('testcategory', 'testaction', {label: 'v1.0.3', value: 22}, {'1':'premium', '5':'foo'}); | ||
tracker.trackEventWithCustomDimensionValues('testcategory', 'testaction', {label: 'v1.0.3', value: 22}, {'1':'premium', '5':'foo'}); | ||
``` | ||
@@ -280,3 +314,3 @@ | ||
```javascript | ||
GoogleAnalytics.setUser('12345678'); | ||
tracker.setUser('12345678'); | ||
``` | ||
@@ -295,74 +329,87 @@ | ||
```javascript | ||
GoogleAnalytics.allowIDFA(true); | ||
tracker.allowIDFA(true); | ||
``` | ||
### setDryRun(enabled) | ||
### setTrackUncaughtExceptions(enabled) | ||
* **enabled (required):** Boolean, indicating if the `dryRun` flag should be enabled or not. | ||
* **enabled (required):** Boolean | ||
When enabled the native library prevents any data from being sent to Google Analytics. This allows you to test or debug the implementation, without your test data appearing in your Google Analytics reports. | ||
Sets if uncaught exceptions should be tracked. This is enabled by default. | ||
```javascript | ||
GoogleAnalytics.setDryRun(true); | ||
tracker.setTrackUncaughtExceptions(true); | ||
``` | ||
### setDispatchInterval(intervalInSeconds) | ||
### setAnonymizeIp(enabled) | ||
* **intervalInSeconds (required):** Number, indicating how often dispatches should be sent | ||
* **enabled (required):** Boolean | ||
Events, screen views, etc, are sent in batches to your tracker. This function allows you to configure how often (in seconds) the batches are sent to your tracker. Recommended to keep this around 20-120 seconds to preserve battery and network traffic. | ||
This is set to 20 seconds by default. | ||
Sets if AnonymizeIp is enabled. This is disabled by default. | ||
If enabled the last octet of the IP address will be removed. | ||
```javascript | ||
GoogleAnalytics.setDispatchInterval(30); | ||
tracker.setAnonymizeIp(true); | ||
``` | ||
### setTrackUncaughtExceptions(enabled) | ||
### setAppName(appName) | ||
* **enabled (required):** Boolean | ||
* **appName (required):** String | ||
Sets if uncaught exceptions should be tracked. This is enabled by default. | ||
Overrides the app name logged in Google Analytics. The Bundle name is used by default. | ||
Note: This has to be set each time the App starts. | ||
```javascript | ||
GoogleAnalytics.setTrackUncaughtExceptions(true); | ||
tracker.setAppName('someAppName'); | ||
``` | ||
### setAnonymizeIp(enabled) | ||
### setSamplingRate(ratio) | ||
* **enabled (required):** Boolean | ||
* **ratio (required):** Number Percentage 0 - 100 | ||
Sets if AnonymizeIp is enabled. This is disabled by default. | ||
If enabled the last octet of the IP address will be removed. | ||
Sets tracker sampling rate. | ||
```javascript | ||
GoogleAnalytics.setAnonymizeIp(true); | ||
tracker.setSamplingRate(50); | ||
``` | ||
### setOptOut(enabled) | ||
## GoogleAnalyticsSettings API | ||
* **enabled (required):** Boolean | ||
Settings are applied across all trackers. | ||
Sets if OptOut is active and disables Google Analytics. This is disabled by default. | ||
Note: This has to be set each time the App starts. | ||
### setDryRun(enabled) | ||
* **enabled (required):** Boolean, indicating if the `dryRun` flag should be enabled or not. | ||
When enabled the native library prevents any data from being sent to Google Analytics. This allows you to test or debug the implementation, without your test data appearing in your Google Analytics reports. | ||
```javascript | ||
GoogleAnalytics.setOptOut(true); | ||
GoogleAnalyticsSettings.setDryRun(true); | ||
``` | ||
### setAppName(appName) | ||
### setDispatchInterval(intervalInSeconds) | ||
* **appName (required):** String | ||
* **intervalInSeconds (required):** Number, indicating how often dispatches should be sent | ||
Overrides the app name logged in Google Analytics. The Bundle name is used by default. | ||
Events, screen views, etc, are sent in batches to your tracker. This function allows you to configure how often (in seconds) the batches are sent to your tracker. Recommended to keep this around 20-120 seconds to preserve battery and network traffic. | ||
This is set to 20 seconds by default. | ||
```javascript | ||
GoogleAnalyticsSettings.setDispatchInterval(30); | ||
``` | ||
### setOptOut(enabled) | ||
* **enabled (required):** Boolean | ||
Sets if OptOut is active and disables Google Analytics. This is disabled by default. | ||
Note: This has to be set each time the App starts. | ||
```javascript | ||
GoogleAnalytics.setAppName('someAppName'); | ||
GoogleAnalyticsSettings.setOptOut(true); | ||
``` | ||
## Google Tag Manager Javascript API | ||
## GoogleTagManager API | ||
The `GoogleTagManager` type is available at `GoogleAnalytics.GoogleTagManager`. If you want to use it alongside `GoogleAnalytics`: | ||
```javascript | ||
import GoogleAnalytics, { GoogleTagManager } from 'react-native-google-analytics-bridge'; | ||
import { GoogleTagManager } from 'react-native-google-analytics-bridge'; | ||
GoogleTagManager.openContainerWithId('GT-NZT48') | ||
@@ -373,3 +420,3 @@ .then(() => GoogleTagManager.stringForKey('pack')) | ||
All methods returns a `Promise`. | ||
Can only be used with one container. All methods returns a `Promise`. | ||
@@ -425,33 +472,14 @@ ### openContainerWithId(containerId) | ||
## Simple A/B-testing | ||
Setting up A/B-testing requires setup of containers in Google Tag Manager, and connecting this with Goals/Experiments in Google Analytics. | ||
### pushDataLayerEvent(dictionary = {}) | ||
##### Parameter(s) | ||
* **dictionary (required):** dictionary An Map<String, Object> containing key and value pairs. | ||
This [blog post](http://www.cbrevik.com/google-tag-manager-and-ab-testing-with-react-native/) details how to do this. [This guide from Google](https://support.google.com/tagmanager/answer/6003007?hl=en) will also prove helpful (and is referenced in the aforementioned blog post). | ||
##### Returns: | ||
* **value:** Boolean | ||
Then you can use our Google Tag Manager implementation to pull values out of the container, and track events in Google Analytics in order to complete "goals". | ||
Push a DataLayer event for Google Analytics through Google Tag Manager. | ||
In this way, the different containers (A/B) the user is given, will be linked to whether or not they accomplish the given goal. | ||
## Google Analytics Logging | ||
There is a divergence in how the iOS and Android versions of the native library handles logging. | ||
[For Android](https://developers.google.com/analytics/devguides/collection/android/v4/advanced#logger) you can check the GA logs with your favorite terminal by using `adb logcat`. | ||
For iOS there is a logger in the [internal library](https://developers.google.com/analytics/devguides/collection/ios/v3/advanced#logger) that writes events to the XCode output window. | ||
In order to control the `logLevel` you can add an item in your `Info.plist` with the key `GAILogLevel`. The value you use is a number which corresponds to your desired log-level: | ||
* 0: None | ||
* 1: Errors | ||
* 2: Warnings | ||
* 3: Info | ||
* 4: Verbose | ||
## Roadmap | ||
- [ ] Ecommerce: checkout process | ||
- [ ] Ecommerce: impressions | ||
- [ ] Campaigns | ||
- [x] Support for A/B testing | ||
- [x] dryRun flag | ||
- [x] Simple ecommerce | ||
- [x] Make the library more configureable | ||
```javascript | ||
GoogleTagManager.pushDataLayerEvent({event: "eventName", pageId: "/home"}) | ||
.then((success) => console.log(success)); | ||
``` |
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
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
35737246
43
829
468