Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
react-native-google-analytics-bridge
Advanced tools
React Native bridge for using native Google Analytics libraries on iOS and Android
Google Analytics Bridge is built to provide an easy interface to the native Google Analytics libraries on both iOS and Android.
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.
You will only have to send in a few parameteres when tracking, e.g:
import { GoogleAnalyticsTracker } from 'react-native-google-analytics-bridge';
let tracker = new GoogleAnalyticsTracker('UA-12345-1');
tracker.trackScreenView('Home');
tracker.trackEvent('testcategory', 'testaction');
0.40
use version 5.0.0
(and up) of this module.0.40
use version 4.0.3
.Install with npm: npm install --save react-native-google-analytics-bridge
Or, install with yarn: yarn add react-native-google-analytics-bridge
Either way, then link with: react-native link react-native-google-analytics-bridge
If it doesn't work immediately after this, consult the manual installation guide. Both Android and iOS has a couple of prerequisite SDKs linked and installed.
Important: Does this library work with Expo? We have to sort of invert the question a bit, because it should be: does Expo work with other libraries? And the answer is no:
The most limiting thing about Expo is that you can’t add in your own native modules without
detach
ing and using ExpoKit.
This includes using create-react-native-app
which also makes use of Expo.
// You have access to three classes in this module:
import {
GoogleAnalyticsTracker,
GoogleTagManager,
GoogleAnalyticsSettings
} from 'react-native-google-analytics-bridge';
// The tracker must be constructed, and you can have multiple:
let tracker1 = new GoogleAnalyticsTracker('UA-12345-1');
let tracker2 = new GoogleAnalyticsTracker('UA-12345-2');
tracker1.trackScreenView('Home');
tracker1.trackEvent('Customer', 'New');
// The GoogleAnalyticsSettings is static, and settings are applied across all trackers:
GoogleAnalyticsSettings.setDispatchInterval(30);
// Setting `dryRun` to `true` lets you test tracking without sending data to GA
GoogleAnalyticsSettings.setDryRun(true);
// 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);
});
Kind: global class
Sets if OptOut is active and disables Google Analytics This has to be set each time the App starts
Kind: static method of GoogleAnalyticsSettings
Param | Type |
---|---|
enabled | boolean |
Sets the trackers dispatch interval This will influence how often batches of events, screen views, etc are sent to your tracker.
Kind: static method of GoogleAnalyticsSettings
Param | Type |
---|---|
intervalInSeconds | number |
Sets if the tracker should have dry run enabled. If dry run is enabled, no analytics data will be sent to your tracker.
Kind: static method of GoogleAnalyticsSettings
Param | Type |
---|---|
enabled | boolean |
Kind: global class
Save all tracker related data that is needed to call native methods with proper data.
Param | Type | Description |
---|---|---|
trackerId | string | Your tracker id, something like: UA-12345-1 |
customDimensionsFieldsIndexMap | Object | Custom dimensions field/index pairs |
Example
import { GoogleAnalyticsTracker } from 'react-native-google-analytics-bridge';
let tracker = new GoogleAnalyticsTracker('UA-12345-1');
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Default | Description |
---|---|---|---|
screenName | string | (Required) The name of the current screen | |
payload | Object |
| (Optional) An object containing the hit payload |
Example
tracker.trackScreenView('Home')
Track the current screen/view. Calling this will also set the "current view" for other calls.
So events tracked will be tagged as having occured on the current view, Home
in this example.
This means it is important to track navigation, especially if events can fire on different views.
Track an event that has occured
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Default | Description |
---|---|---|---|
category | string | (Required) The event category | |
action | string | (Required) The event action | |
payload | Object |
| (Optional) An object containing the hit payload |
label | string | null | (Optional) An optional event label |
value | number |
| (Optional) An optional event value |
Track an event that has occured
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Default | Description |
---|---|---|---|
category | string | (Required) The event category | |
interval | number | (Required) The timing measurement in milliseconds | |
payload | Object |
| (Optional) An object containing the hit payload |
name | string | null | (Required) The timing name |
label | string | null | (Optional) An optional timing label |
Track an exception
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Default | Description |
---|---|---|---|
error | string | (Required) The description of the error | |
fatal | boolean | false | (Optional) A value indiciating if the error was fatal, defaults to false |
payload | Object |
| (Optional) An object containing the hit payload |
Track a social interaction, Facebook, Twitter, etc.
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
network | string | |
action | string | |
targetUrl | string | |
payload | Object | (Optional) An object containing the hit payload |
Sets the current userId for tracking.
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
userId | string | The current userId |
Sets the current clientId for tracking.
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
clientId | string | The current userId |
Sets if IDFA (identifier for advertisers) collection should be enabled
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Default | Description |
---|---|---|---|
enabled | boolean | true | (Optional) Defaults to true |
Sets the trackers appName The Bundle name is used by default
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
appName | string | (Required) |
Sets the trackers appVersion
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
appVersion | string | (Required) |
Sets if AnonymizeIp is enabled If enabled the last octet of the IP address will be removed
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
enabled | boolean | (Required) |
Sets tracker sampling rate.
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
sampleRatio | number | (Required) Percentage 0 - 100 |
Sets the currency for tracking.
Kind: instance method of GoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
currencyCode | string | (Required) The currency ISO 4217 code |
Sets if uncaught exceptions should be tracked Important to note: On iOS this option is set on all trackers. On Android it is set per tracker. If you are using multiple trackers on iOS, this will enable & disable on all trackers.
Kind: instance method of GoogleAnalyticsTracker
Param | Type |
---|---|
enabled | boolean |
Kind: global class
Promise.<boolean>
Promise.<boolean>
Promise.<string>
Promise.<number>
Promise.<boolean>
Promise.<boolean>
Call once to open the container for all subsequent static calls.
Kind: static method of GoogleTagManager
Param | Type |
---|---|
containerId | string |
Promise.<boolean>
Retrieves a boolean value with the given key from the opened container.
Kind: static method of GoogleTagManager
Param | Type |
---|---|
key | string |
Promise.<string>
Retrieves a string with the given key from the opened container.
Kind: static method of GoogleTagManager
Param | Type |
---|---|
key | string |
Promise.<number>
Retrieves a number with the given key from the opened container.
Kind: static method of GoogleTagManager
Param | Type |
---|---|
key | string |
Promise.<boolean>
Push a datalayer event for Google Analytics through Google Tag Manager. The event must have at least one key "event" with event name. You can add optional values on top of that, example: {event: "eventName", pageId: "/home"}
Kind: static method of GoogleTagManager
Param | Type | Description |
---|---|---|
event | Object | An Map<String, Object> containing key and value pairs. It must have at least one key "event" with event name |
FAQs
React Native bridge for using native Google Analytics libraries on iOS and Android
The npm package react-native-google-analytics-bridge receives a total of 135 weekly downloads. As such, react-native-google-analytics-bridge popularity was classified as not popular.
We found that react-native-google-analytics-bridge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.