-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
331 lines (282 loc) · 10.1 KB
/
App.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
Button,
Alert,
} from 'react-native';
import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
import RNInsider from 'react-native-insider';
import InsiderCallbackType from 'react-native-insider/src/InsiderCallbackType';
import InsiderGender from 'react-native-insider/src/InsiderGender';
import ContentOptimizerDataType from 'react-native-insider/src/ContentOptimizerDataType';
import RNInsiderIdentifier from 'react-native-insider/src/InsiderIdentifier';
class App extends React.Component {
componentDidMount() {
RNInsider.init(
'your_partner_name',
'group.com.useinsider.InsiderDemo',
(type, data) => {
switch (type) {
case InsiderCallbackType.NOTIFICATION_OPEN:
console.log('[INSIDER][NOTIFICATION_OPEN]: ', data);
Alert.alert('[INSIDER][NOTIFICATION_OPEN]:', JSON.stringify(data));
break;
case InsiderCallbackType.TEMP_STORE_CUSTOM_ACTION:
console.log('[INSIDER][TEMP_STORE_CUSTOM_ACTION]: ', data);
Alert.alert(
'[INSIDER][TEMP_STORE_CUSTOM_ACTION]: ',
JSON.stringify(data),
);
break;
}
},
);
RNInsider.setActiveForegroundPushView()
RNInsider.registerWithQuietPermission(false);
RNInsider.startTrackingGeofence();
RNInsider.enableIDFACollection(false);
RNInsider.enableIpCollection(false);
RNInsider.enableLocationCollection(false);
RNInsider.enableCarrierCollection(false);
}
render() {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<View style={styles.triggerButton}>
<Button onPress={() => trigger()} title="Trigger" />
</View>
</SafeAreaView>
</>
);
}
}
function trigger() {
// --- USER --- //
// You can crete Insider User and add attributes later on it.
let currentUser = RNInsider.getCurrentUser();
// Setting User Attributes in chainable way.
currentUser
.setName('Insider')
.setSurname('Demo')
.setAge(23)
.setGender(InsiderGender.Other)
.setBirthday(new Date())
.setEmailOptin(true)
.setSMSOptin(false)
.setPushOptin(true)
.setLocationOptin(true)
.setFacebookID('Facebook-ID')
.setTwitterID('Twittter-ID')
.setLanguage('TR')
.setLocale('tr_TR');
// Setting User Identifiers.
let identifiers = new RNInsiderIdentifier();
identifiers.addEmail('mobile@useinsider.com');
identifiers.addPhoneNumber('+901234567');
identifiers.addUserID('CRM-ID');
// Login and Logout
currentUser.logout();
currentUser.login(identifiers);
// Setting custom attributes.
// MARK: Your attribute key should be all lowercased and should not include any special or non Latin characters or any space, otherwise this attribute will be ignored. You can use underscore _.
currentUser.setCustomAttributeWithString(
'string_attribute',
'This is Insider.',
);
currentUser.setCustomAttributeWithInt('int_attribute', 10);
currentUser.setCustomAttributeWithDouble('double_attribute', 20.5);
currentUser.setCustomAttributeWithBoolean('bool_attribute', true);
currentUser.setCustomAttributeWithDate('date_attribute', new Date());
// MARK: You can only call the method with array of string otherwise this event will be ignored.
const arr = ['value1', 'value2', 'value3'];
RNInsider.getCurrentUser().setCustomAttributeWithArray('key', arr);
// --- EVENT --- //
// You can create an event without parameters and call the build method
RNInsider.tagEvent('first_event').build();
// You can create an event then add parameters and call the build method
RNInsider.tagEvent('second_event')
.addParameterWithInt('int_parameter', 10)
.build();
// You can create an object and add the parameters later
let insiderExampleEvent = RNInsider.tagEvent('third_event');
insiderExampleEvent
.addParameterWithString('string_parameter', 'This is Insider.')
.addParameterWithInt('int_parameter', 10)
.addParameterWithDouble('double_parameter', 10.5)
.addParameterWithBoolean('bool_parameter', true)
.addParameterWithDate('date_parameter', new Date());
// MARK: You can only call the method with array of string otherwise this event will be ignored.
insiderExampleEvent.addParameterWithArray('array_parameter', arr);
// Do not forget to call build method once you are done with parameters.
// Otherwise your event will be ignored.
insiderExampleEvent.build();
// --- PRODUCT --- //
// MARK: If any parameter which is passed to this method is nil / null or an empty string, it will return an empty and invalid Insider Product Object. Note that an invalid Insider Product object will be ignored for any product related operations.
// You can crete Insider Product and add attributes later on it.
const taxonomy = ['taxonomy1', 'taxonomy2', 'taxonomy3'];
let insiderExampleProduct = RNInsider.createNewProduct(
'productID',
'productName',
taxonomy,
'imageURL',
1000.5,
'currency',
);
// Setting Product Attributes in chainable way.
insiderExampleProduct
.setColor('color')
.setVoucherName('voucherName')
.setVoucherDiscount(10.5)
.setPromotionName('promotionName')
.setPromotionDiscount(10.5)
.setSize('size')
.setSalePrice(10.5)
.setShippingCost(10.5)
.setQuantity(10)
.setStock(10);
// Setting custom attributes.
// MARK: Your attribute key should be all lowercased and should not include any special or non Latin characters or any space, otherwise this attribute will be ignored. You can use underscore _.
insiderExampleProduct
.setCustomAttributeWithString('string_parameter', 'This is Insider.')
.setCustomAttributeWithInt('int_parameter', 10)
.setCustomAttributeWithDouble('double_parameter', 10.5)
.setCustomAttributeWithBoolean('bool_parameter', true)
.setCustomAttributeWithDate('date_parameter', new Date());
// MARK: You can only call the method with array of string otherwise this event will be ignored.
insiderExampleProduct.setCustomAttributeWithArray('array_parameter', arr);
// --- REVENUE TRACKING --- //
RNInsider.itemPurchased('uniqueSaleID', insiderExampleProduct);
// --- CART REMINDER --- //
// Adding item to cart.
RNInsider.itemAddedToCart(insiderExampleProduct);
// Removing item from the cart.
RNInsider.itemRemovedFromCart('productID');
// Removing all the items from the cart.
// This method will automatically triggered when you call Revenue Tracking.
RNInsider.cartCleared();
// --- RECOMMENDATION ENGINE --- //
// ID comes from your smart recommendation campaign.
// Please follow the language code structure. For instance en_US.
RNInsider.getSmartRecommendation(1, 'tr_TR', 'TRY', recommendation => {
// Handle here
console.log('[INSIDER][getSmartRecommendation]: ', recommendation);
});
RNInsider.getSmartRecommendationWithProduct(
insiderExampleProduct,
1,
'tr_TR',
recommendation => {
// Handle here
console.log(
'[INSIDER][getSmartRecommendationWithProduct]: ',
recommendation,
);
},
);
// --- SOCIAL PROOF --- //
RNInsider.visitProductDetailPage(insiderExampleProduct);
// --- PAGE VISITING --- //
RNInsider.visitHomePage();
RNInsider.visitListingPage(taxonomy);
const insiderExampleProducts = [insiderExampleProduct, insiderExampleProduct];
RNInsider.visitCartPage(insiderExampleProducts);
// --- GDPR --- //
// MARK: Please note that by default our SDK is collecting the data so you don't have to call this function if you are not asking users consents.
// MARK: If you set false, the user will not share any data or receive any push until you set back true.
RNInsider.setGDPRConsent(true);
// --- MESSAGE CENTER --- //
// You can able to see push campaigns in the last 90 days
const startDate = new Date(Date.now() - 86400000);
const endDate = new Date(Date.now() + 86400000);
RNInsider.getMessageCenterData(100, startDate, endDate, messageCenterData => {
// Handle here
console.log('[INSIDER][getMessageCenterData]: ', messageCenterData);
});
// --- CONTENT OPTIMIZER --- //
// String
const contentOptimizerString = RNInsider.getContentStringWithName(
'string_variable_name',
'defaultValue',
ContentOptimizerDataType.ELEMENT,
);
console.log('[INSIDER][getContentStringWithName]: ', contentOptimizerString);
// Boolean
const contentOptimizerBool = RNInsider.getContentBoolWithName(
'bool_variable_name',
true,
ContentOptimizerDataType.ELEMENT,
);
console.log('[INSIDER][getContentBoolWithName]: ', contentOptimizerBool);
// Integer
const contentOptimizerInt = RNInsider.getContentIntWithName(
'int_variable_name',
10,
ContentOptimizerDataType.Element,
);
console.log('[INSIDER][getContentIntWithName]: ', contentOptimizerInt);
}
const styles = StyleSheet.create({
scrollView: {
backgroundColor: Colors.lighter,
},
engine: {
position: 'absolute',
right: 0,
},
body: {
backgroundColor: Colors.white,
},
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
color: Colors.black,
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
color: Colors.dark,
},
highlight: {
fontWeight: '700',
},
triggerButton: {
width: '100%',
height: '100%',
justifyContent: 'center',
alignItems: 'center'
},
footer: {
color: Colors.dark,
fontSize: 12,
fontWeight: '600',
padding: 4,
paddingRight: 12,
textAlign: 'right',
},
});
export default App;