-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathCountlyConfig.js
297 lines (270 loc) · 8.65 KB
/
CountlyConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
import { initialize } from "./Logger.js";
import CountlyConfigApm from "./lib/configuration_interfaces/countly_config_apm.js";
import CountlyConfigSDKInternalLimits from "./lib/configuration_interfaces/countly_config_limits.js";
import CountlyConfigExp from "./lib/configuration_interfaces/countly_config_experimental.js";
import CountlyConfigContent from "./lib/configuration_interfaces/countly_config_content.js";
/**
* Countly SDK React Native Bridge
* https://github.com/Countly/countly-sdk-react-native-bridge
* @Countly
*/
/**
*
* Config Object for Countly Init
* Should be called before Countly "askForNotificationPermission"
*
* @param {String} serverURL server url
* @param {String} appKey application key
*/
class CountlyConfig {
#crashReporting = false;
#apmLegacy = false;
#disableIntentRedirectionCheck = false;
constructor(serverURL, appKey) {
this.serverURL = serverURL;
this.appKey = appKey;
this._countlyConfigApmInstance = new CountlyConfigApm();
this._countlyConfigSDKLimitsInstance = new CountlyConfigSDKInternalLimits();
this._countlyConfigExpInstance = new CountlyConfigExp();
this._countlyConfigContentInstance = new CountlyConfigContent();
}
/**
* Getter to get the APM specific configurations
*/
get apm() {
return this._countlyConfigApmInstance;
}
/**
* Getter to get the SDK internal limits
*/
get sdkInternalLimits() {
return this._countlyConfigSDKLimitsInstance;
}
/**
* Getter to get the experimental configurations
*/
get experimental() {
return this._countlyConfigExpInstance;
}
/**
* Getter to get the content specific configurations
*/
get content() {
return this._countlyConfigContentInstance;
}
get _crashReporting() {
return this.#crashReporting;
}
get _apmLegacy() {
return this.#apmLegacy;
}
get _disableIntentRedirectionCheck() {
return this.#disableIntentRedirectionCheck;
}
/**
* Method to set the server url
*
* @param {String} serverURL server url
*/
setServerURL(serverURL) {
this.serverURL = serverURL;
return this;
}
/**
* Method to set the app key
*
* @param {String} appKey application key
*/
setAppKey(appKey) {
this.appKey = appKey;
return this;
}
/**
* Method to set the device id
*
* @param {String} deviceID device id
*/
setDeviceID(deviceID) {
this.deviceID = deviceID;
return this;
}
/**
* Method to enable countly internal debugging logs
*
* @param {bool} loggingEnabled enable
* if true, countly sdk would log to console.
*/
setLoggingEnabled(loggingEnabled) {
this.loggingEnabled = loggingEnabled;
initialize(loggingEnabled); // initialize React Native SDK logger
return this;
}
/**
* Method to enable crash reporting to report unhandled crashes to Countly
*/
enableCrashReporting() {
this.#crashReporting = true;
return this;
}
/**
* Method to set if the consent feature is enabled.
*
* If set to true, no feature will work without consent being given.
*
* @param {bool} shouldRequireConsent required. True: It is enabled. False:
* It is disabled.
*/
setRequiresConsent(shouldRequireConsent) {
this.shouldRequireConsent = shouldRequireConsent;
return this;
}
/**
* Method to give consent for specific features before init
*
* @param {String[]} consents consents e.g ['location', 'sessions',
* 'attribution', 'push', 'events', 'views', 'crashes', 'users', 'push',
* 'star-rating', 'apm', 'feedback', 'remote-config']
*/
giveConsent(consents) {
this.consents = consents;
return this;
}
/**
* Method to set the user initial location
*
* @param {String} locationCountryCode country code e.g 'TR'
* @param {String} locationCity city e.g 'Istanbul'
* @param {String} locationGpsCoordinates gps coordinates e.g '41.0082,28.9784'
* @param {String} locationIpAddress ip address e.g '10.2.33.12'
*/
setLocation(locationCountryCode, locationCity, locationGpsCoordinates, locationIpAddress) {
this.locationCountryCode = locationCountryCode;
this.locationCity = locationCity;
this.locationGpsCoordinates = locationGpsCoordinates;
this.locationIpAddress = locationIpAddress;
return this;
}
/**
* Method to enable tamper protection. This sets the optional salt to be
* used for calculating the checksum of requested data which will be sent
* with each request
*
* @param {String} tamperingProtectionSalt salt
*/
enableParameterTamperingProtection(tamperingProtectionSalt) {
this.tamperingProtectionSalt = tamperingProtectionSalt;
return this;
}
/**
* @deprecated in 24.4.0 : use 'countlyConfig.apm' interface instead of 'config.enableApm'.
*
* Method to enable application performance monitoring which includes the recording of app start time.
*/
enableApm() {
this.#apmLegacy = true;
return this;
}
/**
* AdditionalIntentRedirectionChecks are enabled by default.
* This method should be used to disable them.
*/
disableAdditionalIntentRedirectionChecks() {
this.#disableIntentRedirectionCheck = true;
return this;
}
/**
* Method to set the push token type
* @deprecated
* Use setPushTokenType() instead to set pushToken
* Use setPushNotificationChannelInformation() instead to set channel information
*
* @param {TokenType} tokenType token type
* @param {String} channelName channel name
* @param {String} channelDescription channel description
*/
pushTokenType(tokenType, channelName, channelDescription) {
this.tokenType = tokenType;
this.channelName = channelName;
this.channelDescription = channelDescription;
return this;
}
/**
* Method to set the push token type
* NB: ONLY FOR iOS
*
* @param {Countly.messagingMode} tokenType token type
* Possible values include 'DEVELOPMENT', 'PRODUCTION', 'ADHOC'.
*/
setPushTokenType(tokenType) {
this.tokenType = tokenType;
return this;
}
/**
* Method to set the push channel name and description
* NB: ONLY FOR ANDROID
*
* @param {String} name channel name
* @param {String} description channel description
*/
setPushNotificationChannelInformation(name, description) {
this.channelName = name;
this.channelDescription = description;
return this;
}
/**
* Method to set the push notification accent color
* NB: ONLY FOR ANDROID
*
* @param {String} accentColor notification accent color
* example '#000000'
*/
setPushNotificationAccentColor(accentColor) {
this.accentColor = accentColor;
return this;
}
/**
* Method to configure intent redirection check
*
* @param {String[]} allowedIntentClassNames allowed intent class names
* @param {String[]} allowedIntentPackageNames allowed intent package name
*/
configureIntentRedirectionCheck(allowedIntentClassNames, allowedIntentPackageNames) {
this.allowedIntentClassNames = allowedIntentClassNames;
this.allowedIntentPackageNames = allowedIntentPackageNames;
return this;
}
/**
* Method to set star rating dialog text
*
* @param {String} starRatingTextTitle title
* @param {String} starRatingTextMessage message
* @param {String} starRatingTextDismiss dismiss
*/
setStarRatingDialogTexts(starRatingTextTitle, starRatingTextMessage, starRatingTextDismiss) {
this.starRatingTextTitle = starRatingTextTitle;
this.starRatingTextMessage = starRatingTextMessage;
this.starRatingTextDismiss = starRatingTextDismiss;
return this;
}
/**
* Report direct user attribution
*
* @param {String} campaignType campaign type
* @param {Object} campaignData campaign data
*/
recordDirectAttribution(campaignType, campaignData) {
this.campaignType = campaignType;
this.campaignData = campaignData;
return this;
}
/**
* Report indirect user attribution
*
* @param {Object} attributionValues attribution values
*/
recordIndirectAttribution(attributionValues) {
this.attributionValues = attributionValues;
return this;
}
}
export default CountlyConfig;