Wiki source code of React native integration
Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
2.1 | 1 | {{box cssClass="floatinginfobox" title="**Page Contents**"}} |
2 | {{toc/}} | ||
3 | {{/box}} | ||
4 | |||
![]() |
11.1 | 5 | = 1. Overview = |
![]() |
4.1 | 6 | |
![]() |
3.1 | 7 | The plugin is located at npmjs repositories [[(npm repositories)>>https://www.npmjs.com/package/react-native-mobigate]] |
![]() |
4.1 | 8 | This plugin is built for: |
9 | |||
10 | * Mobigate SDK version 1.0.4 | ||
11 | |||
![]() |
11.1 | 12 | = 2. Adding SDK to the project = |
![]() |
2.1 | 13 | |
![]() |
4.1 | 14 | **First, install library from the repository with** |
![]() |
2.1 | 15 | |
![]() |
4.1 | 16 | {{code language=""}} |
17 | yarn add react-native-mobigate | ||
18 | {{/code}} | ||
19 | |||
20 | or | ||
21 | |||
22 | {{code language=""}} | ||
23 | npm install react-native-mobigate --save | ||
24 | {{/code}} | ||
25 | |||
26 | **Link newly added plugin** | ||
27 | |||
28 | * **React Native >= 0.60** | ||
29 | Starting from React Native 0.60, [[autolinking>>https://github.com/react-native-community/cli/blob/master/docs/autolinking.md]] makes the installation process simpler | ||
30 | |||
31 | * **React Native <= 0.59** | ||
32 | ** Mostly automatic installation: | ||
33 | {{code language=""}}react-native link react-native-mobigate{{/code}} | ||
![]() |
5.2 | 34 | ** Manual installation:{{showhide id="1" showmessage="Manually link the library on Android" hidemessage="Manually link the library on Android"}}* Add to: android/settings.gradle |
![]() |
4.1 | 35 | |
36 | {{code language="groovy"}} | ||
37 | include ':react-native-mobigate' | ||
38 | project(':react-native-mobigate').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mobigate/android') | ||
39 | {{/code}} | ||
![]() |
5.1 | 40 | * Add to: android/app/build.gradle |
![]() |
4.1 | 41 | |
42 | {{code language="groovy"}} | ||
43 | dependencies { | ||
44 | implementation project(':react-native-mobigate') | ||
45 | } | ||
46 | {{/code}} | ||
![]() |
5.1 | 47 | * Add the MobigatePackage class to your list of exported packages into: android/app/src/main/.../MainApplication.java |
![]() |
4.1 | 48 | |
49 | {{code language="java"}} | ||
50 | ... | ||
51 | import pl.spicymobile.reactmobigate.MobigatePackage; | ||
52 | |||
53 | |||
54 | @Override | ||
55 | protected List<ReactPackage> getPackages() { | ||
56 | return Arrays.<ReactPackage>asList( | ||
57 | new MainReactPackage(), | ||
58 | new MobigatePackage() | ||
59 | ); | ||
60 | } | ||
61 | {{/code}}{{/showhide}} | ||
62 | |||
![]() |
11.1 | 63 | = 3. Api methods = |
![]() |
2.1 | 64 | |
![]() |
5.2 | 65 | To use any method from the plugin add import: |
66 | |||
67 | {{code language="javascript"}} | ||
68 | import Mobigate from 'react-native-mobigate' | ||
69 | {{/code}} | ||
70 | |||
![]() |
11.1 | 71 | == 3.1 SDK initialization == |
![]() |
2.1 | 72 | |
![]() |
5.2 | 73 | You must initialize the library before running it. Use //init(apiKey, options, onSuccess, onError)// method for that: |
74 | |||
75 | **Mobigate.init(apiKey, options, onSuccess, onError)** | ||
76 | |||
77 | (% class="table-bordered table-hover" style="border-color:powderblue" %) | ||
78 | |=(% style="background-color:powderblue" %)Parameter|=(% style="background-color:powderblue" %)Type|=(% style="background-color:powderblue" %)Description | ||
79 | |apiKey|String|Api key provided by your business partner | ||
![]() |
5.4 | 80 | |options|Json Object|SDK configuration |
![]() |
5.2 | 81 | |onSuccess|Function|returns callback object |
82 | |onError|Function|returns callback object | ||
83 | |||
![]() |
6.1 | 84 | {{showhide id="2" showmessage="Options" hidemessage="Options"}} |
![]() |
5.2 | 85 | (% class="table-bordered table-hover" style="border-color:powderblue" %) |
![]() |
5.4 | 86 | |=(% style="background-color:powderblue" %)Name|=(% style="background-color:powderblue" %)Type|=(% style="background-color:powderblue" %)Default|=(% style="background-color:powderblue" %)Description |
87 | | appIdentifier|String| | Application identifier | ||
![]() |
5.5 | 88 | |appInstallationSource |String| | App installation source e.g., google-play, organic. |
89 | |email |String | | Set's user email. | ||
![]() |
8.1 | 90 | |customUserId |String | | You may use your custom userID for marking data. By default we are using device ID and emails for matching. Set it before starting the service using MobigateSDk.Builder method. |
![]() |
5.5 | 91 | | enableUserFields|Json Array | | Enable custom fields in user data. By default MobienceSDK is gathering all identifiers, which it can read. You can choose one of these field: ["email", "imei", "imsi", "msisdn", "mac", "serial"] DODAĆ LINKA DO CONSTANTS. |
92 | | dataGatherPolicy| Json Object| | Enable custom data gater policy. By default MobienceSDK gather all data it can read and hide notification icon. Check below DataGatherPolicy options for more details. | ||
93 | | enableIdProfiles|Boolean |false | turns on / off the IDs profiles system. | ||
![]() |
6.1 | 94 | {{/showhide}} |
![]() |
5.2 | 95 | |
![]() |
6.1 | 96 | {{showhide id="3" showmessage="DataGatherPolicy options" hidemessage="DataGatherPolicy options"}} |
![]() |
5.4 | 97 | (% class="table-bordered table-hover" style="border-color:powderblue" %) |
98 | |=(% style="background-color:powderblue" %)Name|=(% style="background-color:powderblue" %)Type|=(% style="background-color:powderblue" %)Default|=(% style="background-color:powderblue" %)Description | ||
![]() |
6.3 | 99 | | monitorState|String| | Possible monitor states: DODAĆ LINKA DO CONSTANTS. More info about gathering data [[here>>https://wiki.spicymobile.pl/wiki/mobigatesdk/view/Main/mobigatesdkintegrationforandroiddevelopers/#H5.8Datagatherpolicy]] |
100 | |notificationText|String| | if state = Mobigate.DATA_GATHER_POLICY_DEFAULT you can pass custom foreground service notification text | ||
![]() |
6.1 | 101 | {{/showhide}} |
![]() |
5.4 | 102 | |
![]() |
9.1 | 103 | |
![]() |
6.1 | 104 | When the library is already initialized run it. Use //startSDK(onSuccess, onError)// method for that: |
105 | |||
106 | **Mobigate.startSDK(onSuccess, onError)** | ||
107 | |||
108 | (% class="table-bordered table-hover" style="border-color:powderblue" %) | ||
109 | |=(% style="background-color:powderblue" %)Parameter|=(% style="background-color:powderblue" %)Type|=(% style="background-color:powderblue" %)Description | ||
110 | |onSuccess|Function|returns callback object | ||
111 | |onError|Function|returns callback object | ||
112 | |||
113 | {{showhide id="3" showmessage="Example" hidemessage="Example"}} | ||
114 | {{code language="javascript"}} | ||
115 | initLibrary = () => { | ||
116 | if (Platform.OS === 'android') { | ||
117 | Mobigate.init("V0K6jhiIfem6CRWHYZ59Nmj3oFBBKbJsnSsWfR2JNq7ktblOUXwbJoBQTpWnw2uSwW76gpiu2kun50jweTY69B", | ||
118 | { | ||
119 | /*custom options, check docs for more details | ||
120 | appIdentifier: 'customUserAppIdentifier', | ||
121 | appInstallationSource: "customAppInstallationSourcexyz", | ||
122 | email: 'testemail@gmail.com', | ||
123 | userAgent: 'customUserAgent', | ||
124 | customUserId: 'customUserId',*/ | ||
125 | }, (success) => { | ||
126 | /* You can configure custom collectors after init | ||
127 | Mobigate.disableAllDataCollector() | ||
128 | Mobigate.configureDataCollectors(true, [Mobigate.DATA_COLLECTOR_APPS_LIST, | ||
129 | Mobigate.DATA_COLLECTOR_BATTERY, | ||
130 | Mobigate.DATA_COLLECTOR_PHONE_INFO])*/ | ||
131 | |||
132 | Mobigate.startSDK((result) => { | ||
133 | this.setState({ | ||
134 | status: 'started', | ||
135 | }); | ||
136 | |||
137 | }, (errorResult) => { | ||
138 | this.setState({ | ||
139 | status: errorResult, | ||
140 | }); | ||
141 | }) | ||
142 | }, (initError) => { | ||
143 | this.setState({ | ||
144 | status: initError, | ||
145 | }); | ||
146 | }) | ||
147 | }else{ | ||
148 | this.setState({ | ||
149 | status: 'Mobigate SDK supports only Android' | ||
150 | }) | ||
151 | } | ||
152 | } | ||
153 | {{/code}} | ||
154 | {{/showhide}} | ||
155 | |||
![]() |
11.1 | 156 | == 3.2 Tracking in app events == |
![]() |
2.1 | 157 | |
![]() |
11.1 | 158 | === 3.2.1 Overview === |
![]() |
2.1 | 159 | |
![]() |
11.1 | 160 | === 3.2.2 Implementation === |
![]() |
5.5 | 161 | |
![]() |
11.1 | 162 | === 3.2.3 Event categories === |
![]() |
5.5 | 163 | |
![]() |
11.1 | 164 | === 3.2.4 Event parameters === |
![]() |
5.5 | 165 | |
![]() |
11.1 | 166 | == 3.3 Remaining methods == |
![]() |
5.5 | 167 | |
![]() |
11.1 | 168 | |
169 | |||
170 | |||
171 | |||
![]() |
5.5 | 172 | (% class="table-bordered table-hover" style="border-color:powderblue" %) |
173 | |=(% style="background-color:powderblue" %)Name|=(% style="background-color:powderblue" %)Type|=(% style="background-color:powderblue" %)Default|=(% style="background-color:powderblue" %)Description | ||
174 | | | | | | ||
175 | |||
![]() |
11.1 | 176 | = 4. Constants = |
![]() |
2.1 | 177 | |
![]() |
11.1 | 178 | = 5. Sample app = |