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
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
packages/core/docs
packages/core/docs/
build/
node_modules/
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,21 @@ import Mixpanel from '@segment/analytics-react-native-mixpanel'
import GoogleAnalytics from '@segment/analytics-react-native-google-analytics'

analytics
.configure()
.using(Mixpanel, GoogleAnalytics)
.recordScreenViews()
.trackAppLifecycleEvents()
.trackAttributionData()
.ios()
.trackAdvertising()
.trackDeepLinks()
.android()
.disableDevicedId()
.setup("writeKey")
.setup('writeKey', {
using: [Mixpanel, GoogleAnalytics],
recordScreenViews: true,
trackAppLifecycleEvents: true,
trackAttributionData: true,

android: {
flushInterval: 60,
collectDeviceId: true
},
ios: {
trackAdvertising: true,
trackDeepLinks: true
}
})
.then(() =>
console.log('Analytics is ready')
)
Expand Down Expand Up @@ -94,11 +98,9 @@ In your code :
import analytics from '@segment/analytics-react-native'
import GoogleAnalytics from '@segment/analytics-react-native-google-analytics'

await analytics
.configure()
.using(GoogleAnalytics)
// ...
.setup('writeKey')
await analytics.setup('writeKey', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this async? Why is the await required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required because all calls to the React-Native bridge are async. If the bridge fails for any reason it can be handled here so that we don't have uncaught promise rejections. This is the same behaviour as before, so we need to keep the queuing code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it - why is it async again? Is this a React limitation or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, in a production app the thread where the native code is executed is different from the thread where JavaScript is running, so React-Native can only communicate between the two using messages (in iOS they are not even in the same process).

React-Native kinda documents it a bit here:

React Native bridge is asynchronous, so the only way to pass a result to JavaScript is by using callbacks or emitting events (see below).

Also when debugging React-Native, it runs your app in the browser and proxify the bridge over WebSocket (the lets you use the devtools debugger for example). So it should always be assumed that the JS and native part can be run on totally different machines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it - ok!

using: [GoogleAnalytics]
})
```

#### Integrations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ class RNAnalyticsModule(context: ReactApplicationContext): ReactContextBaseJavaM

@ReactMethod
fun setup(options: ReadableMap) {
val android = options.getMap("android")
val builder = Analytics
.Builder(reactApplicationContext, android.getString("writeKey"))
.Builder(reactApplicationContext, options.getString("writeKey"))
.flushQueueSize(options.getInt("flushAt"))

if(options.getBoolean("recordScreenViews")) {
Expand Down
21 changes: 5 additions & 16 deletions packages/core/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

## Index

### Modules

* [ChainedConfiguration](modules/analytics.chainedconfiguration.md)

### Classes

* [Client](classes/analytics.client.md)

### Interfaces

* [Configuration](interfaces/analytics.configuration.md)

### Type aliases

* [Integration](#integration)
* [WriteKey](#writekey)

---

Expand All @@ -26,17 +25,7 @@
**Ƭ Integration**: * `function` | `object`
*

*Defined in analytics.ts:229*

___
<a id="writekey"></a>

### WriteKey

**Ƭ WriteKey**: * `string` &#124; `object`
*

*Defined in analytics.ts:231*
*Defined in [analytics.ts:8](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L8)*

___

83 changes: 44 additions & 39 deletions packages/core/docs/classes/analytics.client.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

* [alias](analytics.client.md#alias)
* [catch](analytics.client.md#catch)
* [configure](analytics.client.md#configure)
* [disable](analytics.client.md#disable)
* [enable](analytics.client.md#enable)
* [flush](analytics.client.md#flush)
Expand All @@ -25,6 +24,7 @@
* [middleware](analytics.client.md#middleware)
* [reset](analytics.client.md#reset)
* [screen](analytics.client.md#screen)
* [setup](analytics.client.md#setup)
* [track](analytics.client.md#track)
* [useNativeConfiguration](analytics.client.md#usenativeconfiguration)

Expand All @@ -38,7 +38,7 @@

**● ready**: *`false`* = false

*Defined in analytics.ts:15*
*Defined in [analytics.ts:96](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L96)*

Whether the client is ready to send events to Segment.

Expand All @@ -54,7 +54,7 @@ ___

▸ **alias**(newId: *`string`*): `Promise`<`void`>

*Defined in analytics.ts:174*
*Defined in [analytics.ts:260](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L260)*

Merge two user identities, effectively connecting two sets of user data as one. This may not be supported by all integrations.

Expand All @@ -75,7 +75,7 @@ ___

▸ **catch**(handler: *[ErrorHandler]()*): `this`

*Defined in analytics.ts:28*
*Defined in [analytics.ts:109](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L109)*

Catch React-Native bridge errors

Expand All @@ -89,39 +89,14 @@ These errors are emitted when calling the native counterpart.

**Returns:** `this`

___
<a id="configure"></a>

### configure

▸ **configure**(): [Configuration](../interfaces/analytics.chainedconfiguration.configuration.md)

*Defined in analytics.ts:102*

Configure the Analytics module.

This method returns a fluent-style API to configure the SDK :

```js
analytics
.configure()
.using(Mixpanel, GoogleAnalytics)
.trackAppLifecycle()
.ios()
.trackDeepLinks()
.setup("YOUR_WRITE_KEY")
```

**Returns:** [Configuration](../interfaces/analytics.chainedconfiguration.configuration.md)

___
<a id="disable"></a>

### disable

▸ **disable**(): `Promise`<`void`>

*Defined in analytics.ts:213*
*Defined in [analytics.ts:299](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L299)*

Completely disable the sending of any analytics data.

Expand All @@ -136,7 +111,7 @@ ___

▸ **enable**(): `Promise`<`void`>

*Defined in analytics.ts:203*
*Defined in [analytics.ts:289](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L289)*

Enable the sending of analytics data. Enabled by default.

Expand All @@ -151,7 +126,7 @@ ___

▸ **flush**(): `Promise`<`void`>

*Defined in analytics.ts:194*
*Defined in [analytics.ts:280](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L280)*

Trigger an upload of all queued events.

Expand All @@ -166,7 +141,7 @@ ___

▸ **group**(groupId: *`string`*, traits?: *`JsonMap`*): `Promise`<`void`>

*Defined in analytics.ts:161*
*Defined in [analytics.ts:247](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L247)*

Associate a user with a group, organization, company, project, or w/e _you_ call them.

Expand All @@ -188,7 +163,7 @@ ___

▸ **identify**(user: *`string`*, traits?: *`JsonMap`*): `Promise`<`void`>

*Defined in analytics.ts:149*
*Defined in [analytics.ts:235](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L235)*

Associate a user with their unique ID and record traits about them.

Expand All @@ -210,7 +185,7 @@ ___

▸ **middleware**(middleware: *[Middleware]()*): `this`

*Defined in analytics.ts:66*
*Defined in [analytics.ts:147](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L147)*

Append a new middleware to the middleware chain.

Expand Down Expand Up @@ -248,7 +223,7 @@ ___

▸ **reset**(): `Promise`<`void`>

*Defined in analytics.ts:184*
*Defined in [analytics.ts:270](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L270)*

Reset any user state that is cached on the device.

Expand All @@ -263,7 +238,7 @@ ___

▸ **screen**(name: *`string`*, properties?: *`JsonMap`*): `Promise`<`void`>

*Defined in analytics.ts:135*
*Defined in [analytics.ts:221](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L221)*

Record the screens or views your users see.

Expand All @@ -278,14 +253,44 @@ When a user views a screen in your app, you'll want to record that here. For som

**Returns:** `Promise`<`void`>

___
<a id="setup"></a>

### setup

▸ **setup**(writeKey: *`string`*, configuration?: *[Configuration](../interfaces/analytics.configuration.md)*): `Promise`<`void`>

*Defined in [analytics.ts:186](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L186)*

Setup the Analytics module. All calls made before are queued and executed if the configuration was successful.

```js
await analytics.setup('YOUR_WRITE_KEY', {
using: [Mixpanel, GoogleAnalytics],
trackAppLifecycleEvents: true,
ios: {
trackDeepLinks: true
}
})
```

**Parameters:**

| Param | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| writeKey | `string` | - | Your Segment.io write key |
| `Default value` configuration | [Configuration](../interfaces/analytics.configuration.md) | {} | An optional [Configuration](../interfaces/analytics.configuration.md) object. |

**Returns:** `Promise`<`void`>

___
<a id="track"></a>

### track

▸ **track**(event: *`string`*, properties?: *`JsonMap`*): `Promise`<`void`>

*Defined in analytics.ts:117*
*Defined in [analytics.ts:203](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L203)*

Record the actions your users perform.

Expand All @@ -307,7 +312,7 @@ ___

▸ **useNativeConfiguration**(): `this`

*Defined in analytics.ts:78*
*Defined in [analytics.ts:159](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L159)*

Use the native configuration.

Expand Down
Loading