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.
There already exists an excellent library for Google Analytics tracking by lwansbrough which uses just JavaScript, why do we need a native bridge?
The key difference is that with this native bridge you get a lot of the metadata handled automatically by the Google Analytics library. This will include the device UUID, viewport size, OS version etc. With the pure javascript variant you will have to pull this information out via a native bridge (e.g. with rebeccahughes' DeviceInfo) in order to track it.
If you do not need any of the device metadata, then we would definitely recommend checking out lwansbroughs repository.
npm install --save react-native-google-analytics-bridge
rnpm link
With this, rnpm will do most of the heavy lifting for linking, but you will still need to do some of the manual steps below.
These are step 5 and 6 from the iOS installation, and 4 and 5 from the Android installation. Specifically for Android step 4, you'll have to add the tracking id.
npm install --save react-native-google-analytics-bridge
Add Files to <your project>
.node_modules
➜ react-native-google-analytics-bridge
➜ ios
➜ RCTGoogleAnalyticsBridge
and add the RCTGoogleAnalyticsBridge.xcodeproj
file.npm install --save react-native-google-analytics-bridge
android/setting.gradle
...
include ':GoogleAnalyticsBridge', ':app'
project(':GoogleAnalyticsBridge').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-analytics-bridge/android')
android/app/build.gradle
...
dependencies {
...
compile project(':GoogleAnalyticsBridge')
}
MainActivity.java
// Step 1; import package:
import com.idehub.GoogleAnalyticsBridge.GoogleAnalyticsBridgePackage;
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
// Step 2; register package, with your GA tracking id:
.addPackage(new GoogleAnalyticsBridgePackage("UA-12345-1"))
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
...
}
...
AndroidManifest.xml
has INTERNET
and ACCESS_NETWORK_STATE
permissions<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
...
const GoogleAnalytics = require('react-native-google-analytics-bridge');
GoogleAnalytics.trackScreenView('Home');
GoogleAnalytics.trackEvent('testcategory', 'testaction');
At the moment the implementation only exposes two methods:
This method only takes one parameter, the name of the current screen view. E. g. GoogleAnalytics.trackScreenView('Home')
.
Important: Calling this will also set the "current view" in this session. So events tracked will be tagged as having occured on the current view, Home
in this example. So it is important to keep this up-to-date.
This method takes takes two required parameters, the event category and action. The optionalValues can be label, and value.
E. g. GoogleAnalytics.trackEvent('testcategory', 'testaction');
or GoogleAnalytics.trackEvent('testcategory', 'testaction', { label: "v1.0.3", value: 22 });
Note: Label is a string, while value must be a number.
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.