Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ class RNAnalyticsModule(context: ReactApplicationContext): ReactContextBaseJavaM
@ReactMethod
fun getAnonymousId(promise: Promise) =
promise.resolve(analytics.getAnalyticsContext().traits().anonymousId())

@ReactMethod
fun putDeviceToken(deviceToken: String) =
analytics.getAnalyticsContext().putDeviceToken(deviceToken)
}

private fun optionsFrom(context: ReadableMap?, integrations: ReadableMap?): Options {
Expand Down
19 changes: 19 additions & 0 deletions packages/core/docs/classes/analytics.client.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@ analytics.middleware(async ({next, context}) =>

**Returns:** `this`

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

### putDeviceToken

▸ **putDeviceToken**(deviceToken: *`string`*): `Promise`<`void`>

*Defined in analytics.ts:317*

Set a device token.

**Parameters:**

| Name | Type |
| ------ | ------ |
| deviceToken | `string` |

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

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

Expand Down
5 changes: 5 additions & 0 deletions packages/core/ios/RNAnalytics/RNAnalytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,9 @@ - (NSDictionary*)withContextAndIntegrations :(NSDictionary*)context :(NSDictiona
resolver(anonymousId);
}

RCT_EXPORT_METHOD(putDeviceToken:(NSString*)deviceToken)
{
[SEGAnalytics.sharedAnalytics putDeviceToken:deviceToken];
}

@end
1 change: 1 addition & 0 deletions packages/core/src/__mocks__/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
getAnonymousId: jest.fn(),
group: jest.fn(),
identify: jest.fn(),
putDeviceToken: jest.fn(),
reset: jest.fn(),
screen: jest.fn(),
setup: jest.fn(),
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/__tests__/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ it('does .disable()', testCall('disable'))

it('does .getAnonymousId()', testCall('getAnonymousId'))

it('does .putDeviceToken()', () => testCall('putDeviceToken')('d34db33f'))

it('logs uncaught bridge errors', async () => {
const error = {
message: 'test-error'
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ export module Analytics {
return Bridge.getAnonymousId()
}

/** Set a device token. */
public async putDeviceToken(deviceToken: string) {
await this.wrapper.wait()

Bridge.putDeviceToken(deviceToken)
}

private handleError(error: Error) {
const { handlers } = this

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface Bridge {
enable(): Promise<void>
disable(): Promise<void>
getAnonymousId(): Promise<string>
putDeviceToken(deviceToken: string): Promise<void>
}

const bridge: Bridge = NativeModules.RNAnalytics
Expand Down