1 | import { UnavailabilityError } from '@unimodules/core';
|
2 | import { Platform } from 'react-native';
|
3 | import ExponentSegment from './ExponentSegment';
|
4 | export function initialize(options) {
|
5 | if (!ExponentSegment.initialize) {
|
6 | throw new UnavailabilityError('expo-analytics-segment', 'initialize');
|
7 | }
|
8 | const platformWriteKey = Platform.select({
|
9 | ios: options.iosWriteKey,
|
10 | android: options.androidWriteKey,
|
11 | });
|
12 | if (platformWriteKey) {
|
13 | ExponentSegment.initialize(platformWriteKey);
|
14 | }
|
15 | else {
|
16 | throw new Error('You must provide a platform-specific write key to initialize Segment.');
|
17 | }
|
18 | }
|
19 | export function identify(userId) {
|
20 | if (!ExponentSegment.identify) {
|
21 | throw new UnavailabilityError('expo-analytics-segment', 'identify');
|
22 | }
|
23 | ExponentSegment.identify(userId);
|
24 | }
|
25 | export function identifyWithTraits(userId, traits, options = null) {
|
26 | if (!ExponentSegment.identifyWithTraits) {
|
27 | throw new UnavailabilityError('expo-analytics-segment', 'identifyWithTraits');
|
28 | }
|
29 | ExponentSegment.identifyWithTraits(userId, traits, options);
|
30 | }
|
31 | export function group(groupId) {
|
32 | if (!ExponentSegment.group) {
|
33 | throw new UnavailabilityError('expo-analytics-segment', 'group');
|
34 | }
|
35 | ExponentSegment.group(groupId);
|
36 | }
|
37 | export function groupWithTraits(groupId, traits, options = null) {
|
38 | if (!ExponentSegment.groupWithTraits) {
|
39 | throw new UnavailabilityError('expo-analytics-segment', 'groupWithTraits');
|
40 | }
|
41 | ExponentSegment.groupWithTraits(groupId, traits, options);
|
42 | }
|
43 | export async function alias(newId, options = null) {
|
44 | if (!ExponentSegment.alias) {
|
45 | throw new UnavailabilityError('expo-analytics-segment', 'alias');
|
46 | }
|
47 | return await ExponentSegment.alias(newId, options);
|
48 | }
|
49 | export function reset() {
|
50 | if (!ExponentSegment.reset) {
|
51 | throw new UnavailabilityError('expo-analytics-segment', 'reset');
|
52 | }
|
53 | ExponentSegment.reset();
|
54 | }
|
55 | export function track(event) {
|
56 | if (!ExponentSegment.track) {
|
57 | throw new UnavailabilityError('expo-analytics-segment', 'track');
|
58 | }
|
59 | ExponentSegment.track(event);
|
60 | }
|
61 | export function trackWithProperties(event, properties, options = null) {
|
62 | if (!ExponentSegment.trackWithProperties) {
|
63 | throw new UnavailabilityError('expo-analytics-segment', 'trackWithProperties');
|
64 | }
|
65 | ExponentSegment.trackWithProperties(event, properties, options);
|
66 | }
|
67 | export function screen(screenName) {
|
68 | if (!ExponentSegment.screen) {
|
69 | throw new UnavailabilityError('expo-analytics-segment', 'screen');
|
70 | }
|
71 | ExponentSegment.screen(screenName);
|
72 | }
|
73 | export function screenWithProperties(event, properties, options = null) {
|
74 | if (!ExponentSegment.screenWithProperties) {
|
75 | throw new UnavailabilityError('expo-analytics-segment', 'screenWithProperties');
|
76 | }
|
77 | ExponentSegment.screenWithProperties(event, properties, options);
|
78 | }
|
79 | export function flush() {
|
80 | if (!ExponentSegment.flush) {
|
81 | throw new UnavailabilityError('expo-analytics-segment', 'flush');
|
82 | }
|
83 | ExponentSegment.flush();
|
84 | }
|
85 | export async function getEnabledAsync() {
|
86 | if (!ExponentSegment.getEnabledAsync) {
|
87 | throw new UnavailabilityError('expo-analytics-segment', 'getEnabledAsync');
|
88 | }
|
89 | const isEnabledNumber = await ExponentSegment.getEnabledAsync();
|
90 | return !!isEnabledNumber;
|
91 | }
|
92 | export async function setEnabledAsync(enabled) {
|
93 | if (!ExponentSegment.setEnabledAsync) {
|
94 | throw new UnavailabilityError('expo-analytics-segment', 'setEnabledAsync');
|
95 | }
|
96 | await ExponentSegment.setEnabledAsync(enabled);
|
97 | }
|
98 |
|
\ | No newline at end of file |