在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):idehub/react-native-google-analytics-bridge开源软件地址(OpenSource Url):https://github.com/idehub/react-native-google-analytics-bridge开源编程语言(OpenSource Language):Objective-C 53.8%开源软件介绍(OpenSource Introduction):Deprecation noticeOn November 13th 2018 Google issued the following statement:
The message is quite clear, and therefore I am officially deprecating this library. If you want to continue using Google's solutions for analytics, I recommend you move to Google Analytics for Firebase instead. For React Native, there is a great library called react-native-firebase which implements Analytics (and other Firebase solutions). I will continue to support this library for minor fixes, but no major changes will occur. The repository itself will be archived sometime in 2019. Thanks to everyone who have used or contributed to this library! - Christian (@cbrevik) GoogleAnalyticsBridgeGoogle Analytics Bridge is built to provide an easy interface to the native Google Analytics libraries on both iOS and Android. Why a native bridge? Why not use just JavaScript?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"); Version 6 breaking changes!If you are upgrading to version 6 from an older version, read this wiki post for important details. The newest version of this library has a new API surface. The API changes are in most cases backwards-compatible. Content
Installation and linking libraries
Install with npm: Or, install with yarn: Either way, then link with: 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:
This includes using Usage// 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);
});
// You can also register Function Call tag handlers when the container is open.
GoogleTagManager.registerFunctionCallTagHandler(
"some_function", // Must be equal to Function Name field when the tag was configured.
(functionName, tagArguments) => {
// functionName is passed for convenience. In this example it will be equal to "some_function".
// tagArguments is an object and is populated based on Tag configuration in TagManager interface.
console.log("Handling Function Call tag:", functionName);
}
) JavaScript APITable of Contents
GoogleAnalyticsSettingsSettings which are applied across all trackers. setOptOutSets if OptOut is active and disables Google Analytics. This is disabled by default. Note: This has to be set each time the App starts. Parameters
ExamplesGoogleAnalyticsSettings.setOptOut(true); setDispatchIntervalSets the trackers dispatch interval. 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. Parameters
ExamplesGoogleAnalyticsSettings.setDispatchInterval(30); setDryRunWhen 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. Parameters
ExamplesGoogleAnalyticsSettings.setDryRun(true); GoogleAnalyticsTrackerExamples// Constructing a tracker is simple:
import { GoogleAnalyticsTracker } from "react-native-google-analytics-bridge";
const tracker = new GoogleAnalyticsTracker("UA-12345-1");
tracker.trackScreenView("Home");
// You can have multiple trackers if you have several tracking ids
const tracker2 = new GoogleAnalyticsTracker("UA-12345-2"); // One optional feature as well is constructing a tracker with a CustomDimensionsFieldIndexMap, to map custom dimension field names to index keys:
const fieldIndexMap = { customerType: 1 };
const tracker3 = new GoogleAnalyticsTracker("UA-12345-3", fieldIndexMap);
// This is because the Google Analytics API expects custom dimensions to be tracked by index keys, and not field names.
// Here the underlying logic will transform the custom dimension, so what ends up being sent to GA is { 1: 'Premium' }:
tracker3.trackScreenView("Home", { customDimensions: { customerType: "Premium" } });
// If you do not use a CustomDimensionsFieldIndexMap, you will have to use index as keys instead for custom dimensions:
tracker.trackScreenView("Home", { customDimensions: { 1: "Premium" } }); trackScreenViewTrack 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, Parameters
Examplestracker.trackScreenView('Home'); // With payload:
const payload = { impressionList: "Sale", impressionProducts: [ { id: "PW928", name: "Premium bundle" } ] };
tracker.trackScreenView("SplashModal", payload); trackEventTrack an event that has occured Parameters
Examplestracker.trackEvent("DetailsButton", "Click"); // Track event with label and value
tracker.trackEvent("AppVersionButton", "Click", { label: "v1.0.3", value: 22 }); // Track with a payload (ecommerce in this case):
const product = {
id: "P12345",
name: "Android Warhol T-Shirt",
category: "Apparel/T-Shirts",
brand: "Google",
variant: "Black",
price: 29.2,
quantity: 1,
couponCode: "APPARELSALE"
};
const transaction = {
id: "T12345",
affiliation: "Google Store - Online",
revenue: 37.39,
tax: 2.85,
shipping: 5.34,
couponCode: "SUMMER2013"
};
const productAction = {
transaction,
action: 7 // Purchase action, see ProductActionEnum
}
const payload = { products: [ product ], productAction: productAction }
tracker.trackEvent("FinalizeOrderButton", "Click", null, payload); trackTimingTrack a timing measurement Parameters
Examplestracker.trackTiming("testcategory", 2000, { name: "LoadList" }); // name metadata is required // With optional label:
tracker.trackTiming("testcategory", 2000, { name: "LoadList", label: "v1.0.3" }); trackExceptionTrack an exception Parameters
Examplestry {
...
} catch(error) {
tracker.trackException(error.message, false);
} trackSocialInteractionTrack a social interaction, Facebook, Twitter, etc. Parameters
|