![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
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);
});
There are three classes which can be imported from the react-native-google-analytics-bridge
module.
Hit
Hit
Hit
Hit
Hit
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 |
Kind: global class
Properties
Name | Type | Description |
---|---|---|
products | Array.<Product> | (Optional) Products which an action has occured on. |
productAction | ProductAction | (Optional) The action which occured on the products. Required if products is not empty. |
impressionProducts | Array.<Product> | (Optional) Products which has had an impression. |
impressionList | string | (Optional) The list which product impressions occured on. Required if impressionProducts is not empty. |
impressionSource | string | (Optional) The source which impression occured from (Android only). |
customDimensions | CustomDimensionsByIndex | CustomDimensionsByField | (Optional) Custom dimensions. |
customMetrics | CustomMetrics | (Optional) Custom metrics. |
utmCampaignUrl | string | (Optional) UTM campaign URL. |
startSession | number | (Optional) Start new session. |
All properties on the payload is optional. Preferably leave them empty unless you actually need to send something extra.
HitPayload
Adds a product in the payload.
productAction
must also be set on the payload if you add products.
Kind: instance method of HitPayload
Param | Type |
---|---|
product | Product |
HitPayload
Adds a product impression.
impressionList
must also be set on the payload if you add impression products.
Kind: instance method of HitPayload
Param | Type |
---|---|
product | Product |
Kind: global class
Properties
Name | Type | Default | Description |
---|---|---|---|
payload | HitPayload |
| (Optional) Payload to send with the hit. |
Base class for all Hits.
Hit
Kind: global class
Extends: Hit
Export:
Properties
Name | Type | Description |
---|---|---|
screenName | string | The current screen name. |
Kind: static class of ScreenHit
Creates an instance of ScreenHit.
Param | Type |
---|---|
screenName | string |
Hit
Kind: global class
Extends: Hit
Export:
Properties
Name | Type | Default | Description |
---|---|---|---|
category | string | The event category | |
action | string | The event action | |
label | string | null | The event label |
value | number |
| The event value |
Kind: static class of EventHit
Creates an instance of EventHit.
Param | Type | Default |
---|---|---|
category | string | |
action | string | |
[label] | string | null |
[value] | number |
|
Hit
Kind: global class
Extends: Hit
Export:
Properties
Name | Type | Default | Description |
---|---|---|---|
category | string | The timing category | |
interval | number | The timing interval | |
name | string | The timing name | |
label | string | null | The timing label |
Kind: static class of TimingHit
Creates an instance of TimingHit.
Param | Type | Default |
---|---|---|
category | string | |
interval | number | |
name | string | |
[label] | string | null |
Hit
Kind: global class
Extends: Hit
Export:
Properties
Name | Type | Default | Description |
---|---|---|---|
error | string | The error | |
fatal | boolean | false | If the error was fatal. Defaults to false. |
Kind: static class of ExceptionHit
Creates an instance of ExceptionHit.
Param | Type | Default |
---|---|---|
error | string | |
[fatal] | boolean | false |
Hit
Kind: global class
Extends: Hit
Export:
Properties
Name | Type | Description |
---|---|---|
network | string | The social network |
action | string | The social action. +1, like, etc |
targetUrl | string | The target url. |
Kind: static class of SocialHit
Creates an instance of SocialHit.
Param | Type |
---|---|
network | string |
action | string |
targetUrl | string |
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 NewGoogleAnalyticsTracker
Param | Type |
---|---|
screenName | string |
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type |
---|---|
hit | ScreenHit |
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type | Default |
---|---|---|
category | string | |
action | string | |
[label] | string | null |
[value] | number |
|
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type |
---|---|
hit | EventHit |
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type | Default |
---|---|---|
category | string | |
interval | number | |
name | string | |
[label] | string | null |
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type |
---|---|
hit | TimingHit |
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type | Default |
---|---|---|
error | string | |
[fatal] | boolean | false |
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type |
---|---|
hit | ExceptionHit |
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type |
---|---|
network | string |
action | string |
targetUrl | string |
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type |
---|---|
hit | SocialHit |
Sets the current userId for tracking.
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
userId | string | The current userId |
Sets the current clientId for tracking.
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
clientId | string | The current userId |
Sets if IDFA (identifier for advertisers) collection should be enabled
Kind: instance method of NewGoogleAnalyticsTracker
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 NewGoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
appName | string | (Required) The app name |
Sets the trackers appVersion
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
appVersion | string | (Required) The app version |
Sets if AnonymizeIp is enabled If enabled the last octet of the IP address will be removed
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
enabled | boolean | (Required) Enable anonymize IP |
Sets tracker sampling rate.
Kind: instance method of NewGoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
sampleRatio | number | (Required) Percentage 0 - 100 |
Sets the currency for tracking.
Kind: instance method of NewGoogleAnalyticsTracker
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 NewGoogleAnalyticsTracker
Param | Type | Description |
---|---|---|
enabled | boolean | Should enable uncaught exception tracking |
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.