-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
7,653 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
.DS_Store | ||
|
||
*.iml | ||
*.log | ||
build/ | ||
coverage/ | ||
node_modules/ | ||
xcuserdata/ | ||
vendor/ | ||
.bundle/ | ||
.gradle | ||
|
||
packages/test-app/project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
## Environment | ||
|
||
This project is a Yarn workspace, npm is not supported. To install dependencies run : | ||
|
||
```bash | ||
$ yarn | ||
``` | ||
|
||
### Useful commands | ||
|
||
- Build everything: | ||
```bash | ||
$ yarn build | ||
``` | ||
- Build the `@segment/react-native` package: | ||
```bash | ||
$ yarn core build | ||
``` | ||
|
||
### Architecture | ||
|
||
- `packages/core`: the `@segment/react-native` module | ||
- `docs`: the generated TypeScript documentation, commited using a `lint-staged` hook | ||
- `packages/integration-build`: | ||
- `integrations.yml`: the unique source of truth for supported integrations | ||
- `generators`: a set of generators using `integrations.yml` | ||
- `gen-integrations.js`: generates `@segment/react-native-*` packages in `build/` | ||
- `gen-readme.js`: updates `README.md` [Integrations](README.md#integrations) section | ||
- `test-app` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Segment.io, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
# @segment/react-native | ||
|
||
The hassle-free way to add analytics to your React-Native app. | ||
|
||
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) ![CircleCI](https://img.shields.io/circleci/project/github/segment/analytics-react-native.svg) ![Codecov](https://img.shields.io/codecov/c/github/segment/analytics-react-native.svg) ![npm](https://img.shields.io/npm/v/@segment/react-native.svg) | ||
|
||
## Prerequisite | ||
|
||
#### Android | ||
|
||
- Gradle 4+ | ||
- Build Tools 3+ | ||
|
||
#### iOS | ||
|
||
- CocoaPods (**recommended**) | ||
- [Don't have CocoaPods setup?](#setup-cocoapods-in-an-existing-project) | ||
- or [manually install `Analytics`](#ios-support-without-cocoapods) | ||
|
||
## Installation | ||
|
||
```bash | ||
$ yarn add @segment/react-native | ||
$ yarn react-native link | ||
``` | ||
|
||
> All integrations have the same version as `@segment/react-native` | ||
## Usage | ||
|
||
See the [API docs](packages/core/docs/classes/analytics.client.md) for more details. | ||
|
||
```js | ||
import analytics from '@segment/react-native' | ||
import Mixpanel from '@segment/react-native-mixpanel' | ||
import GoogleAnalytics from '@segment/react-native-google-analytics' | ||
|
||
analytics | ||
.configure() | ||
.using(Mixpanel, GoogleAnalytics) | ||
.recordScreenViews() | ||
.trackAppLifecycleEvents() | ||
.trackAttributionData() | ||
.ios() | ||
.recordBluetooth() | ||
.trackAdvertising() | ||
.trackDeepLinks() | ||
.android() | ||
.disableDevicedId() | ||
.setup("writeKey") | ||
.then(() => | ||
console.log('Analytics is ready') | ||
) | ||
.catch(err => | ||
console.error('Something went wrong', err) | ||
) | ||
|
||
analytics.track('Pizza Eaten') | ||
analytics.screen('Home') | ||
``` | ||
|
||
### Sending data to destinations | ||
|
||
<!-- Based on https://segment.com/docs/sources/mobile/android/#sending-data-to-destinations --> | ||
|
||
There are two ways to send data to your analytics services through this library: | ||
|
||
1. [Through the Segment servers](#cloud-based-connection-modes) | ||
2. [Directly from the device using bundled SDK’s](#packaging-device-based-destination-sdks) | ||
|
||
**Note**: Refer to the specific destination’s docs to see if your tool must be bundled in the app or sent server-side. | ||
|
||
#### Cloud-based Connection Modes | ||
|
||
When an destination’s SDK is not packaged, but it is enabled via your dashboard, the request goes through the Segment REST API, and is routed to the service’s server-side API as [described here](https://segment.com/docs/integrations/#connection-modes). | ||
|
||
#### Packaging Device-based destination SDKs | ||
|
||
By default, our `@segment/react-native` packages does not contain any device-based destinations. | ||
|
||
We recommend using device-based destinations on a need-to-use basis to reduce the size of your application, and avoid running into the dreaded 65k method limit on Android. | ||
|
||
If you would like to package device-based destinations, first search for the dependency you need using [the list below](#integrations). | ||
You'll need to run `react-native link` and add it in the `.using()` configuration method. Example using Google Analytics : | ||
|
||
```bash | ||
$ yarn add @segment/react-native-google-analytics | ||
$ yarn react-native link | ||
``` | ||
|
||
In your code : | ||
|
||
```js | ||
import analytics from '@segment/react-native' | ||
import GoogleAnalytics from '@segment/react-native-google-analytics' | ||
|
||
await analytics | ||
.configure() | ||
.using(GoogleAnalytics) | ||
// ... | ||
.setup('writeKey') | ||
|
||
``` | ||
|
||
#### Integrations | ||
|
||
<!-- AUTOGEN:INTEGRATIONS:BEGIN --> | ||
| Name | iOS | Android | npm package | | ||
| -------------------------------------------------------------------------------------------------- | ------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------ | | ||
| [Adjust](https://www.npmjs.com/package/@segment/react-native-adjust) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-adjust`](https://www.npmjs.com/package/@segment/react-native-adjust) | | ||
| [Amplitude](https://www.npmjs.com/package/@segment/react-native-amplitude) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-amplitude`](https://www.npmjs.com/package/@segment/react-native-amplitude) | | ||
| [Appboy](https://www.npmjs.com/package/@segment/react-native-appboy) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-appboy`](https://www.npmjs.com/package/@segment/react-native-appboy) | | ||
| [AppsFlyer](https://www.npmjs.com/package/@segment/react-native-appsflyer) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-appsflyer`](https://www.npmjs.com/package/@segment/react-native-appsflyer) | | ||
| [Branch](https://www.npmjs.com/package/@segment/react-native-branch) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-branch`](https://www.npmjs.com/package/@segment/react-native-branch) | | ||
| [Bugsnag](https://www.npmjs.com/package/@segment/react-native-bugsnag) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-bugsnag`](https://www.npmjs.com/package/@segment/react-native-bugsnag) | | ||
| [ComScore](https://www.npmjs.com/package/@segment/react-native-comscore-ios) | :white_check_mark: | :x: | [`@segment/react-native-comscore-ios`](https://www.npmjs.com/package/@segment/react-native-comscore-ios) | | ||
| [Countly](https://www.npmjs.com/package/@segment/react-native-countly) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-countly`](https://www.npmjs.com/package/@segment/react-native-countly) | | ||
| [Crittercism](https://www.npmjs.com/package/@segment/react-native-crittercism) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-crittercism`](https://www.npmjs.com/package/@segment/react-native-crittercism) | | ||
| [Facebook App Events](https://www.npmjs.com/package/@segment/react-native-facebook-app-events-ios) | :white_check_mark: | :x: | [`@segment/react-native-facebook-app-events-ios`](https://www.npmjs.com/package/@segment/react-native-facebook-app-events-ios) | | ||
| [Firebase](https://www.npmjs.com/package/@segment/react-native-firebase) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-firebase`](https://www.npmjs.com/package/@segment/react-native-firebase) | | ||
| [Flurry](https://www.npmjs.com/package/@segment/react-native-flurry) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-flurry`](https://www.npmjs.com/package/@segment/react-native-flurry) | | ||
| [Google Analytics](https://www.npmjs.com/package/@segment/react-native-google-analytics) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-google-analytics`](https://www.npmjs.com/package/@segment/react-native-google-analytics) | | ||
| [Intercom](https://www.npmjs.com/package/@segment/react-native-intercom) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-intercom`](https://www.npmjs.com/package/@segment/react-native-intercom) | | ||
| [Localytics](https://www.npmjs.com/package/@segment/react-native-localytics) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-localytics`](https://www.npmjs.com/package/@segment/react-native-localytics) | | ||
| [Mixpanel](https://www.npmjs.com/package/@segment/react-native-mixpanel) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-mixpanel`](https://www.npmjs.com/package/@segment/react-native-mixpanel) | | ||
| [Quantcast](https://www.npmjs.com/package/@segment/react-native-quantcast-android) | :x: | :white_check_mark: | [`@segment/react-native-quantcast-android`](https://www.npmjs.com/package/@segment/react-native-quantcast-android) | | ||
| [Taplytics](https://www.npmjs.com/package/@segment/react-native-taplytics-ios) | :white_check_mark: | :x: | [`@segment/react-native-taplytics-ios`](https://www.npmjs.com/package/@segment/react-native-taplytics-ios) | | ||
| [Tapstream](https://www.npmjs.com/package/@segment/react-native-tapstream-android) | :x: | :white_check_mark: | [`@segment/react-native-tapstream-android`](https://www.npmjs.com/package/@segment/react-native-tapstream-android) | | ||
<!-- AUTOGEN:INTEGRATIONS:END --> | ||
|
||
|
||
## Troubleshooting | ||
|
||
### iOS support without CocoaPods | ||
|
||
<!-- Based on https://segment.com/docs/sources/mobile/ios/#dynamic-framework-for-manual-installation --> | ||
|
||
We **highly recommend** using Cocoapods. | ||
|
||
However, if you cannot use Cocoapods, you can manually install our dynamic framework allowing you to send data to Segment and on to enabled cloud-mode destinations. We do not support sending data to bundled, device-mode integrations outside of Cocoapods. | ||
|
||
Here are the steps for installing manually: | ||
|
||
1. Download the [latest built SDK](https://github.com/segmentio/analytics-ios/releases), and unzip the zip file. | ||
2. Drag the unzipped Analytics.framework folder into your Xcode project. | ||
Make sure to check `Copy items if needed`. | ||
![Add Analytics.framework](docs/ios/add-analytics-framework.png) | ||
3. In the `General` tab for your project, search for `Embedded Binaries` and add the `Analytics.framework`. | ||
![Embed Analytics.framework](docs/ios/embed-analytics-framework.png) | ||
|
||
Please note, if you are choosing to not use a dependency manager, you must keep files up-to-date with regularly scheduled, manual updates. | ||
|
||
### Setup CocoaPods in an existing project | ||
|
||
1. Check that `ios/Podfile` doesn't exist | ||
2. `cd ios` | ||
3. `pod init` | ||
4. Open `Podfile` | ||
5. Edit your app `target` to have these `pod` declarations and the `Add new pods below this line` comment : | ||
```ruby | ||
target 'MyReactNativeApp' do | ||
pod 'React', :path => '../node_modules/react-native' | ||
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga' | ||
|
||
# Add new pods below this line | ||
end | ||
``` | ||
6. `pod install` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"name": "react-native-analytics", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"private": true, | ||
"workspaces": { | ||
"packages": [ | ||
"packages/*" | ||
], | ||
"nohoist": [ | ||
"**/react-native", | ||
"**/react-native/**" | ||
] | ||
}, | ||
"scripts": { | ||
"core": "yarn workspace @segment/react-native run", | ||
"integrations": "yarn workspace @local/integrations run", | ||
"test-app": "yarn workspace @local/test-app run", | ||
"build:core": "yarn core build", | ||
"build:integrations": "yarn integrations build", | ||
"build:test-app": "yarn test-app build", | ||
"build": "run-s build:{core,integrations,test-app}", | ||
"test:core": "yarn core test", | ||
"test": "run-p test:*", | ||
"cz": "git-cz", | ||
"precommit": "lint-staged", | ||
"commitmsg": "commitlint -E GIT_PARAMS" | ||
}, | ||
"commitlint": { | ||
"extends": [ | ||
"@commitlint/config-conventional" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "cz-conventional-changelog" | ||
} | ||
}, | ||
"lint-staged": { | ||
"packages/core/ts/**/*.ts": [ | ||
"yarn core docs --", | ||
"git add packages/core/docs" | ||
], | ||
"packages/integrations/integrations.yml": [ | ||
"yarn integrations generate:readme --", | ||
"git add README.md" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^7.0.0", | ||
"@commitlint/config-conventional": "^7.0.1", | ||
"codecov": "^3.0.4", | ||
"commitizen": "^2.10.1", | ||
"commitlint-circle": "^1.0.0", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^7.2.0", | ||
"npm-run-all": "^4.1.3", | ||
"rimraf": "^2.6.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'json' | ||
package = JSON.parse(File.read('./package.json')) | ||
|
||
Pod::Spec.new do |s| | ||
s.name = 'RNAnalytics' | ||
s.version = package['version'] | ||
s.summary = package['description'] | ||
s.description = <<-DESC | ||
Analytics for iOS provides a single API that lets you | ||
integrate with over 100s of tools. | ||
DESC | ||
|
||
s.homepage = 'http://segment.com/' | ||
s.social_media_url = 'https://twitter.com/segment' | ||
s.license = { :type => 'MIT' } | ||
s.author = { 'Segment' => '[email protected]' } | ||
s.source = { :git => 'https://github.com/segmentio/analytics-react-native.git', :tag => s.version.to_s } | ||
|
||
s.platform = :ios, '9.0' | ||
s.source_files = 'ios/**/*.{m,h}' | ||
s.static_framework = true | ||
|
||
s.dependency 'Analytics' | ||
s.dependency 'React' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
maven { url 'https://maven.google.com' } | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.1.4' | ||
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.60' | ||
} | ||
} | ||
|
||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion = '26.0.3' | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName '1.0' | ||
} | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "$rootDir/../node_modules/react-native/android" | ||
name 'React Native (local)' | ||
} | ||
mavenCentral() | ||
} | ||
|
||
|
||
dependencies { | ||
api 'com.segment.analytics.android:analytics:4.+' | ||
|
||
api 'com.facebook.react:react-native:+' | ||
api 'org.jetbrains.kotlin:kotlin-stdlib:1.2.+' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest package="com.segment.analytics.reactnative.core"/> |
Oops, something went wrong.