Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 49 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,40 @@ NOTE: This project is currently in development and is covered by Segment's [Firs

## Table of Contents

- [Installation](#installation)
- [Permissions](#permissions)
- [Expo](#expo-installation)
- [Migration](#migrating)
- [Usage](#usage)
- [Setting up the client](#setting-up-the-client)
- [Client options](#client-options)
- [Usage with hooks](#usage-with-hooks)
- [useAnalytics](#useanalytics)
- [Usage without hooks](#usage-without-hooks)
- [Client methods](#client-methods)
- [Track](#track)
- [Screen](#screen)
- [Identify](#identify)
- [Group](#group)
- [Alias](#alias)
- [Reset](#reset)
- [Flush](#flush)
- [Advanced Cleanup](#advanced-cleanup)
- [Automatic screen tracking](#automatic-screen-tracking)
- [React Navigation](#react-navigation)
- [React Native Navigation](#react-native-navigation)
- [Plugin Architecture](#plugin-types)
- [Contributing](#contributing)
- [Code of Conduct](#code-of-conduct)
- [License](#license)
- [@segment/analytics-react-native ![circleci](#segmentanalytics-react-native-circlecicircleci-url)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Expo Installation](#expo-installation)
- [Permissions](#permissions)
- [Migrating](#migrating)
- [Usage](#usage)
- [Setting up the client](#setting-up-the-client)
- [Client Options](#client-options)
- [iOS Deep Link Tracking Setup](#ios-deep-link-tracking-setup)
- [Usage with hooks](#usage-with-hooks)
- [useAnalytics()](#useanalytics)
- [Usage without hooks](#usage-without-hooks)
- [Client methods](#client-methods)
- [Track](#track)
- [Screen](#screen)
- [Identify](#identify)
- [Group](#group)
- [Alias](#alias)
- [Reset](#reset)
- [Flush](#flush)
- [(Advanced) Cleanup](#advanced-cleanup)
- [Automatic screen tracking](#automatic-screen-tracking)
- [React Navigation](#react-navigation)
- [React Native Navigation](#react-native-navigation)
- [Plugins + Timeline architecture](#plugins--timeline-architecture)
- [Plugin Types](#plugin-types)
- [Destination Plugins](#destination-plugins)
- [Adding Plugins](#adding-plugins)
- [Writing your own Plugins](#writing-your-own-plugins)
- [Example Plugins](#example-plugins)
- [Contributing](#contributing)
- [Code of Conduct](#code-of-conduct)
- [License](#license)

## Installation

Expand Down Expand Up @@ -109,12 +117,26 @@ You must pass at least the `writeKey`. Additional configuration options are list
| `maxBatchSize` | 1000 | How many events to send to the API at once |
| `maxEventsToRetry` | 1000 | How many events to keep around for to retry sending if the initial request failed |
| `trackAppLifecycleEvents` | false | Enable automatic tracking for [app lifecycle events](https://segment.com/docs/connections/spec/mobile/#lifecycle-events): application installed, opened, updated, backgrounded) |
| `trackDeepLinks` | false | Enable automatic tracking for when the user opens the app via a deep link |
| `trackDeepLinks` | false | Enable automatic tracking for when the user opens the app via a deep link (Note: Requires additional setup on iOS, [see instructions](#ios-deep-link-tracking-setup)) |
| `defaultSettings` | undefined | Settings that will be used if the request to get the settings from Segment fails |
| `autoAddSegmentDestination`| true | Set to false to skip adding the SegmentDestination plugin |

\* The default value of `debug` will be false in production.

### iOS Deep Link Tracking Setup
*Note: This is only required for iOS if you are using the `trackDeepLinks` option. Android does not require any additional setup*

To track deep links in iOS you must add the following to your `AppDelegate.m` file:

```objc
- (BOOL)application:(UIApplication *)application
openURL: (NSURL *)url
options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {

[AnalyticsReactNative trackDeepLink:url withOptions:options];
return YES;
}
```
### Usage with hooks

In order to use the `useAnalytics` hook within the application, we will additionally need to wrap the application in
Expand Down
13 changes: 12 additions & 1 deletion example/android/.project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<name>AnalyticsReactNativeExample</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
Expand All @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1644522731203</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions example/android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
10 changes: 10 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="segmentreactnative" android:host="hello" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="segmentreactnative.com"
android:pathPrefix="/deepLink"
/>
</intent-filter>
</activity>
<activity
android:name="com.zoontek.rnbootsplash.RNBootSplashActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
package com.example.segmentanalyticsreactnative;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.os.Build;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.segmentanalyticsreactnative.AnalyticsReactNativeModule;
import com.sovranreactnative.SovranModule;
import com.zoontek.rnbootsplash.RNBootSplash;

import java.util.Hashtable;

public class MainActivity extends ReactActivity {

/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* Returns the name of the main component registered from JavaScript. This is
* used to schedule
* rendering of the component.
*/
@Override
Expand All @@ -21,4 +34,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RNBootSplash.init(R.drawable.bootsplash, MainActivity.this);
}

@Override
protected void onResume() {
super.onResume();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,32 @@
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

import com.segmentanalyticsreactnative.AnalyticsReactNativePackage;

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost =
new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for AnalyticsReactNativeExample:
// packages.add(new MyReactNativePackage());
packages.add(new AnalyticsReactNativePackage());
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

return packages;
}
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for
// AnalyticsReactNativeExample:
// packages.add(new MyReactNativePackage());
packages.add(new AnalyticsReactNativePackage());
return packages;
}

@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
protected String getJSMainModuleName() {
return "index";
}
};

@Override
public ReactNativeHost getReactNativeHost() {
Expand All @@ -48,7 +46,9 @@ public ReactNativeHost getReactNativeHost() {
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled
initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); //// Remove this line if you don't want
//// Flipper enabled

}

/**
Expand All @@ -60,9 +60,9 @@ private static void initializeFlipper(Context context, ReactInstanceManager reac
if (BuildConfig.DEBUG) {
try {
/*
We use reflection here to pick up the class that initializes Flipper,
since Flipper library is not available in release mode
*/
* We use reflection here to pick up the class that initializes Flipper,
* since Flipper library is not available in release mode
*/
Class<?> aClass = Class.forName("com.segmentanalyticsreactnativeExample.ReactNativeFlipper");
aClass
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
20F357AE24636CDF00C146DC /* AnalyticsReactNativeExample-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AnalyticsReactNativeExample-Bridging-Header.h"; sourceTree = "<group>"; };
20F357AF24636CDF00C146DC /* File.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; };
4D7192F03A36A017E887435B /* Pods-AnalyticsReactNativeExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AnalyticsReactNativeExample.release.xcconfig"; path = "Target Support Files/Pods-AnalyticsReactNativeExample/Pods-AnalyticsReactNativeExample.release.xcconfig"; sourceTree = "<group>"; };
82A9DBCD27ADC2ED00E38216 /* AnalyticsReactNativeExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = AnalyticsReactNativeExample.entitlements; path = AnalyticsReactNativeExample/AnalyticsReactNativeExample.entitlements; sourceTree = "<group>"; };
871719007ECC5EAD276C345C /* Pods-AnalyticsReactNativeExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AnalyticsReactNativeExample.debug.xcconfig"; path = "Target Support Files/Pods-AnalyticsReactNativeExample/Pods-AnalyticsReactNativeExample.debug.xcconfig"; sourceTree = "<group>"; };
BCEA90A70F4BEAD7E9FA28B2 /* libPods-AnalyticsReactNativeExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AnalyticsReactNativeExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
Expand All @@ -50,6 +51,7 @@
13B07FAE1A68108700A75B9A /* AnalyticsReactNativeExample */ = {
isa = PBXGroup;
children = (
82A9DBCD27ADC2ED00E38216 /* AnalyticsReactNativeExample.entitlements */,
02771A7425486F20008AD4BC /* GoogleService-Info.plist */,
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
Expand Down Expand Up @@ -195,7 +197,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
};
7A2FB6969CDA2F7083356BAB /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -278,6 +280,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = AnalyticsReactNativeExample/AnalyticsReactNativeExample.entitlements;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = NO;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -309,6 +312,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = AnalyticsReactNativeExample/AnalyticsReactNativeExample.entitlements;
CURRENT_PROJECT_VERSION = 1;
ENABLE_BITCODE = NO;
"EXCLUDED_ARCHS[sdk=*]" = arm64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
ReferencedContainer = "container:AnalyticsReactNativeExample.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array/>
</dict>
</plist>
1 change: 1 addition & 0 deletions example/ios/AnalyticsReactNativeExample/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <React/RCTBridgeModule.h>
@import segment_analytics_react_native;

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>

Expand Down
9 changes: 9 additions & 0 deletions example/ios/AnalyticsReactNativeExample/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#import <React/RCTRootView.h>
#import "RNBootSplash.h"
@import AdSupport;
@import React;
@import segment_analytics_react_native;

@implementation AppDelegate

Expand All @@ -30,7 +32,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[RNBootSplash initWithStoryboard:@"LaunchScreen" rootView:rootView];
return YES;
}

- (BOOL)application:(UIApplication *)application
openURL: (NSURL *)url
options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {

[AnalyticsReactNative trackDeepLink:url withOptions:options];
return YES;
}

Expand Down
3 changes: 2 additions & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ PODS:
- React-Core
- segment-analytics-react-native (2.1.6-beta):
- React-Core
- sovran-react-native
- segment-analytics-react-native-plugin-idfa (0.2.0-beta):
- React-Core
- sovran-react-native (0.2.4):
Expand Down Expand Up @@ -458,7 +459,7 @@ SPEC CHECKSUMS:
RNCAsyncStorage: b49b4e38a1548d03b74b30e558a1d18465b94be7
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
RNGestureHandler: bf572f552ea324acd5b5464b8d30755b2d8c1de6
segment-analytics-react-native: 2efa452e7ce2b8b59cf2dd9335e208c963ebbbbe
segment-analytics-react-native: 1651b31be11bee997e39ff7ababd296f00f7492a
segment-analytics-react-native-plugin-idfa: 2dc6e38506a5b034db4a4cf16db48643b2f356a2
sovran-react-native: 1b68d70aaa2d96489e0338eaf3a4cbf92688c793
Yoga: 3f5bfc54ce164fcd5b5d7f9f4232182d6298dd56
Expand Down
Loading