UNPKG

5.85 kBPlain TextView Raw
1import { UnavailabilityError } from '@unimodules/core';
2
3import ExpoAmplitude from './ExpoAmplitude';
4
5export interface AmplitudeTrackingOptions {
6 disableAdid?: boolean;
7 disableCarrier?: boolean;
8 disableCity?: boolean;
9 disableCountry?: boolean;
10 disableDeviceBrand?: boolean;
11 disableDeviceManufacturer?: boolean;
12 disableDeviceModel?: boolean;
13 disableDMA?: boolean;
14 disableIDFV?: boolean;
15 disableIPAddress?: boolean;
16 disableLanguage?: boolean;
17 disableLatLng?: boolean;
18 disableOSName?: boolean;
19 disableOSVersion?: boolean;
20 disablePlatform?: boolean;
21 disableRegion?: boolean;
22 disableVersionName?: boolean;
23}
24
25export async function initializeAsync(apiKey: string): Promise<void> {
26 if (!ExpoAmplitude.initializeAsync) {
27 throw new UnavailabilityError('Amplitude', 'initializeAsync');
28 }
29 return await ExpoAmplitude.initializeAsync(apiKey);
30}
31
32export async function setUserIdAsync(userId: string): Promise<void> {
33 if (!ExpoAmplitude.setUserIdAsync) {
34 throw new UnavailabilityError('Amplitude', 'setUserIdAsync');
35 }
36 return await ExpoAmplitude.setUserIdAsync(userId);
37}
38
39export async function setUserPropertiesAsync(userProperties: {
40 [name: string]: any;
41}): Promise<void> {
42 if (!ExpoAmplitude.setUserPropertiesAsync) {
43 throw new UnavailabilityError('Amplitude', 'setUserPropertiesAsync');
44 }
45 return await ExpoAmplitude.setUserPropertiesAsync(userProperties);
46}
47
48export async function clearUserPropertiesAsync(): Promise<void> {
49 if (!ExpoAmplitude.clearUserPropertiesAsync) {
50 throw new UnavailabilityError('Amplitude', 'clearUserPropertiesAsync');
51 }
52 return await ExpoAmplitude.clearUserPropertiesAsync();
53}
54
55export async function logEventAsync(eventName: string): Promise<void> {
56 if (!ExpoAmplitude.logEventAsync) {
57 throw new UnavailabilityError('Amplitude', 'logEventAsync');
58 }
59 return await ExpoAmplitude.logEventAsync(eventName);
60}
61
62export async function logEventWithPropertiesAsync(
63 eventName: string,
64 properties: { [name: string]: any }
65): Promise<void> {
66 if (!ExpoAmplitude.logEventWithPropertiesAsync) {
67 throw new UnavailabilityError('Amplitude', 'logEventWithPropertiesAsync');
68 }
69 return await ExpoAmplitude.logEventWithPropertiesAsync(eventName, properties);
70}
71
72export async function setGroupAsync(groupType: string, groupNames: string[]): Promise<void> {
73 if (!ExpoAmplitude.setGroupAsync) {
74 throw new UnavailabilityError('Amplitude', 'setGroupAsync');
75 }
76 return await ExpoAmplitude.setGroupAsync(groupType, groupNames);
77}
78
79export async function setTrackingOptionsAsync(options: AmplitudeTrackingOptions): Promise<void> {
80 if (!ExpoAmplitude.setTrackingOptionsAsync) {
81 throw new UnavailabilityError('Amplitude', 'setTrackingOptionsAsync');
82 }
83 return await ExpoAmplitude.setTrackingOptionsAsync(options);
84}
85
86/*
87 * Legacy methods for backwards-compatibility.
88 * These should be removed in SDK 41
89 */
90
91/**
92 * @deprecated Use initializeAsync instead
93 */
94export async function initialize(apiKey: string): Promise<void> {
95 console.warn(
96 "'Amplitude.initialize' is deprecated in favor of 'Amplitude.initializeAsync'. Please use the new method, which contains no user-facing changes."
97 );
98 return await initializeAsync(apiKey);
99}
100
101/**
102 * @deprecated Use setUserIdAsync instead
103 */
104export async function setUserId(userId: string): Promise<void> {
105 console.warn(
106 "'Amplitude.setUserId' is deprecated in favor of 'Amplitude.setUserIdAsync'. Please use the new method, which contains no user-facing changes."
107 );
108 return await setUserIdAsync(userId);
109}
110
111/**
112 * @deprecated Use setUserPropertiesAsync instead
113 */
114export async function setUserProperties(userProperties: { [name: string]: any }): Promise<void> {
115 console.warn(
116 "'Amplitude.setUserProperties' is deprecated in favor of 'Amplitude.setUserPropertiesAsync'. Please use the new method, which contains no user-facing changes."
117 );
118 return await setUserPropertiesAsync(userProperties);
119}
120
121/**
122 * @deprecated Use clearUserPropertiesAsync instead
123 */
124export async function clearUserProperties(): Promise<void> {
125 console.warn(
126 "'Amplitude.clearUserProperties' is deprecated in favor of 'Amplitude.clearUserPropertiesAsync'. Please use the new method, which contains no user-facing changes."
127 );
128 return await clearUserPropertiesAsync();
129}
130
131/**
132 * @deprecated Use logEventAsync instead
133 */
134export async function logEvent(eventName: string): Promise<void> {
135 console.warn(
136 "'Amplitude.logEvent' is deprecated in favor of 'Amplitude.logEventAsync'. Please use the new method, which contains no user-facing changes."
137 );
138 return await logEventAsync(eventName);
139}
140
141/**
142 * @deprecated Use logEventWithPropertiesAsync instead
143 */
144export async function logEventWithProperties(
145 eventName: string,
146 properties: { [name: string]: any }
147): Promise<void> {
148 console.warn(
149 "'Amplitude.logEventWithProperties' is deprecated in favor of 'Amplitude.logEventWithPropertiesAsync'. Please use the new method, which contains no user-facing changes."
150 );
151 return await logEventWithPropertiesAsync(eventName, properties);
152}
153
154/**
155 * @deprecated Use setGroupAsync instead
156 */
157export async function setGroup(groupType: string, groupNames: string[]): Promise<void> {
158 console.warn(
159 "'Amplitude.setGroup' is deprecated in favor of 'Amplitude.setGroupAsync'. Please use the new method, which contains no user-facing changes."
160 );
161 return await setGroupAsync(groupType, groupNames);
162}
163
164/**
165 * @deprecated Use setTrackingOptionsAsync instead
166 */
167export async function setTrackingOptions(options: AmplitudeTrackingOptions): Promise<void> {
168 console.warn(
169 "'Amplitude.setTrackingOptions' is deprecated in favor of 'Amplitude.setTrackingOptionsAsync'. Please use the new method, which contains no user-facing changes."
170 );
171 return await setTrackingOptionsAsync(options);
172}