forked from agustinus/react-native-firebase-gtm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
99 lines (88 loc) · 3.77 KB
/
index.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
"use strict";
import { NativeModules } from 'react-native';
const RCTFirebaseGtm = NativeModules.ReactNativeFirebaseGtm;
const RCTFirebaseRemoteConfig = NativeModules.ReactNativeFirebaseRemoteConfig;
export const ReactNativeFirebaseGtm = {
/**
* @param {String}json The json object to process
*/
push: function (eventName, json) {
return RCTFirebaseGtm.push(eventName, json);
},
/**
* Set user property to Gtm
* Note that:
* - up to 25 user property may be set
* - name and value are limited to max 24 and 36 chars
* @see: https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics
*
* @param {string} name - length: 1~24 chars
* @param {string} value - length: 1~36 chars
*/
setUserProperty: function(name, value='') {
// Convert value to string.
// In iOS, non-string such as NSNumber cannot implicitly be converted to NSString
value = '' + value;
return RCTFirebaseGtm.setUserProperty(name, value);
},
kFIRConstant: {
kFIREventViewItem: RCTFirebaseGtm.kFIREventViewItem,
kFIREventBeginCheckout: RCTFirebaseGtm.kFIREventBeginCheckout,
kFIREventEcommercePurchase: RCTFirebaseGtm.kFIREventEcommercePurchase,
kFIREventAddToCart: RCTFirebaseGtm.kFIREventAddToCart,
kFIREventRemoveFromCart: RCTFirebaseGtm.kFIREventRemoveFromCart,
kFIREventViewSearchResults: RCTFirebaseGtm.kFIREventViewSearchResults,
kFIREventSelectContent: RCTFirebaseGtm.kFIREventSelectContent,
kFIRParameterCurrency: RCTFirebaseGtm.kFIRParameterCurrency,
kFIRParameterCheckoutStep: RCTFirebaseGtm.kFIRParameterCheckoutStep,
kFIRParameterItemList: RCTFirebaseGtm.kFIRParameterItemList,
kFIRParameterItemID: RCTFirebaseGtm.kFIRParameterItemID,
kFIRParameterItemName: RCTFirebaseGtm.kFIRParameterItemName,
kFIRParameterItemCategory: RCTFirebaseGtm.kFIRParameterItemCategory,
kFIRParameterItemBrand: RCTFirebaseGtm.kFIRParameterItemBrand,
kFIRParameterPrice: RCTFirebaseGtm.kFIRParameterPrice,
kFIRParameterIndex: RCTFirebaseGtm.kFIRParameterIndex,
kFIRParameterQuantity: RCTFirebaseGtm.kFIRParameterQuantity,
kFIRParameterTransactionID: RCTFirebaseGtm.kFIRParameterTransactionID,
kFIRParameterValue: RCTFirebaseGtm.kFIRParameterValue,
kFIRParameterShipping: RCTFirebaseGtm.kFIRParameterShipping,
kFIRParameterCoupon: RCTFirebaseGtm.kFIRParameterCoupon,
},
}
export const ReactNativeFirebaseRemoteConfig = {
/**
* Tell Firebase to fetch new/cached values from Firebase Remote Config,
*
* @param {number} cacheTime - cache time in seconds, default: 43200, which is 12 hours
*/
fetchRemoteConfig: function(cacheTime=43200) {
RCTFirebaseRemoteConfig.fetchRemoteConfig(cacheTime);
},
setDefaults: function(defaults={}) {
RCTFirebaseRemoteConfig.setDefaults(defaults);
},
/**
* Async function to return the remote config value (as String) for given key
* @param {string} key - The name of the key
* @return {string} the value fetched in String
*/
getStringAsync: function(key) {
return new Promise((resolve) => {
RCTFirebaseRemoteConfig.getString(key, (value) => {
resolve(value);
});
});
},
/**
* Async function to return the remote config value (as Boolean) for given key
* @param {string} key - The name of the key
* @return {boolean} the value fetched in Boolean
*/
getBooleanAsync: function(key) {
return new Promise((resolve) => {
RCTFirebaseRemoteConfig.getBoolean(key, (value) => {
resolve(value);
});
});
},
}