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