Skip to content

Commit 48e6956

Browse files
prayanshBrandon Sneed
andauthored
[Feature] add support for supplying defaultProjectSettings (#178)
* feat(android): add support for defaultProjectSettings * test(react-native): add tests for new configuration property * feat(ios): added iOS support for project settings * test(copyright): updated * fix(ios): bumped pod versions * fix(ios): dont cache pod files for ci * fix(ios): pod install needs repo update flag * fix(ios): moved podspec to appropriate version * test(ci): small change to test ci Co-authored-by: Brandon Sneed <[email protected]>
1 parent 735d666 commit 48e6956

File tree

15 files changed

+134
-40
lines changed

15 files changed

+134
-40
lines changed

packages/core/RNAnalytics.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Pod::Spec.new do |s|
2020
s.source_files = 'ios/**/*.{m,h}'
2121
s.static_framework = true
2222

23-
s.dependency 'Analytics', '~> 3.8'
23+
s.dependency 'Analytics', '3.9.0'
2424
s.dependency 'React'
2525
end

packages/core/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repositories {
3939
}
4040

4141
dependencies {
42-
api 'com.segment.analytics.android:analytics:4.5.0'
42+
api 'com.segment.analytics.android:analytics:4.6.0'
4343

4444
api 'com.facebook.react:react-native:+'
4545
api "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : defaultKotlinVersion}"

packages/core/android/src/main/java/com/segment/analytics/reactnative/core/RNAnalyticsModule.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ class RNAnalyticsModule(context: ReactApplicationContext): ReactContextBaseJavaM
166166
this.trackApplicationLifecycleEvents(writeKey)
167167
}
168168

169+
if(options.hasKey("defaultProjectSettings")) {
170+
builder.defaultProjectSettings(Utils.toValueMap(options.getMap("defaultProjectSettings")))
171+
}
172+
169173
RNAnalytics.setupCallbacks(analytics)
170174

171175
singletonJsonConfig = json
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.segment.analytics.reactnative.core
2+
3+
import com.facebook.react.bridge.ReadableArray
4+
import com.facebook.react.bridge.ReadableMap
5+
import com.facebook.react.bridge.ReadableType
6+
import com.segment.analytics.ValueMap
7+
8+
object Utils {
9+
fun toArray(readableArray: ReadableArray?): Array<Any?> {
10+
if (readableArray == null) {
11+
return arrayOfNulls(0)
12+
}
13+
val array = arrayOfNulls<Any>(readableArray.size())
14+
for (i in 0 until readableArray.size()) {
15+
val type = readableArray.getType(i)
16+
when (type) {
17+
ReadableType.Null -> array[i] = null
18+
ReadableType.Boolean -> array[i] = readableArray.getBoolean(i)
19+
ReadableType.Number -> array[i] = readableArray.getDouble(i)
20+
ReadableType.String -> array[i] = readableArray.getString(i)
21+
ReadableType.Map -> array[i] = toValueMap(readableArray.getMap(i))
22+
ReadableType.Array -> array[i] = toArray(readableArray.getArray(i))
23+
}
24+
}
25+
return array
26+
}
27+
28+
fun toValueMap(readableMap: ReadableMap?): ValueMap {
29+
if (readableMap == null) {
30+
return ValueMap()
31+
}
32+
val map = ValueMap()
33+
val iterator = readableMap.keySetIterator()
34+
while (iterator.hasNextKey()) {
35+
val key = iterator.nextKey()
36+
val type = readableMap.getType(key)
37+
when (type) {
38+
ReadableType.Null -> map[key] = null
39+
ReadableType.Boolean -> map[key] = readableMap.getBoolean(key)
40+
ReadableType.Number -> map[key] = readableMap.getDouble(key)
41+
ReadableType.String -> map[key] = readableMap.getString(key)
42+
ReadableType.Map -> map[key] = toValueMap(readableMap.getMap(key))
43+
ReadableType.Array -> map[key] = toArray(readableMap.getArray(key))
44+
}
45+
}
46+
return map
47+
}
48+
}

packages/core/docs/classes/analytics.client.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
**● ready**: *`false`* = false
4141

42-
*Defined in [analytics.ts:96](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L96)*
42+
*Defined in [analytics.ts:104](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L104)*
4343

4444
Whether the client is ready to send events to Segment.
4545

@@ -55,7 +55,7 @@ ___
5555

5656
**alias**(newId: *`string`*, options?: *[Options]()*): `Promise`<`void`>
5757

58-
*Defined in [analytics.ts:266](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L266)*
58+
*Defined in [analytics.ts:274](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L274)*
5959

6060
Merge two user identities, effectively connecting two sets of user data as one. This may not be supported by all integrations.
6161

@@ -77,7 +77,7 @@ ___
7777

7878
**catch**(handler: *[ErrorHandler]()*): `this`
7979

80-
*Defined in [analytics.ts:111](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L111)*
80+
*Defined in [analytics.ts:119](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L119)*
8181

8282
Catch React-Native bridge errors
8383

@@ -98,7 +98,7 @@ ___
9898

9999
**disable**(): `Promise`<`void`>
100100

101-
*Defined in [analytics.ts:305](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L305)*
101+
*Defined in [analytics.ts:313](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L313)*
102102

103103
Completely disable the sending of any analytics data.
104104

@@ -113,7 +113,7 @@ ___
113113

114114
**enable**(): `Promise`<`void`>
115115

116-
*Defined in [analytics.ts:295](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L295)*
116+
*Defined in [analytics.ts:303](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L303)*
117117

118118
Enable the sending of analytics data. Enabled by default.
119119

@@ -128,7 +128,7 @@ ___
128128

129129
**flush**(): `Promise`<`void`>
130130

131-
*Defined in [analytics.ts:286](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L286)*
131+
*Defined in [analytics.ts:294](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L294)*
132132

133133
Trigger an upload of all queued events.
134134

@@ -143,7 +143,7 @@ ___
143143

144144
**getAnonymousId**(): `Promise`<`string`>
145145

146-
*Defined in [analytics.ts:310](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L310)*
146+
*Defined in [analytics.ts:318](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L318)*
147147

148148
Retrieve the anonymousId.
149149

@@ -156,7 +156,7 @@ ___
156156

157157
**group**(groupId: *`string`*, traits?: *[JsonMap]()*, options?: *[Options]()*): `Promise`<`void`>
158158

159-
*Defined in [analytics.ts:253](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L253)*
159+
*Defined in [analytics.ts:261](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L261)*
160160

161161
Associate a user with a group, organization, company, project, or w/e _you_ call them.
162162

@@ -179,7 +179,7 @@ ___
179179

180180
**identify**(user: *`string`*, traits?: *[JsonMap]()*, options?: *[Options]()*): `Promise`<`void`>
181181

182-
*Defined in [analytics.ts:240](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L240)*
182+
*Defined in [analytics.ts:248](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L248)*
183183

184184
Associate a user with their unique ID and record traits about them.
185185

@@ -202,7 +202,7 @@ ___
202202

203203
**middleware**(middleware: *[Middleware]()*): `this`
204204

205-
*Defined in [analytics.ts:149](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L149)*
205+
*Defined in [analytics.ts:157](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L157)*
206206

207207
Append a new middleware to the middleware chain.
208208

@@ -240,7 +240,7 @@ ___
240240

241241
**reset**(): `Promise`<`void`>
242242

243-
*Defined in [analytics.ts:276](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L276)*
243+
*Defined in [analytics.ts:284](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L284)*
244244

245245
Reset any user state that is cached on the device.
246246

@@ -255,7 +255,7 @@ ___
255255

256256
**screen**(name: *`string`*, properties?: *[JsonMap]()*, options?: *[Options]()*): `Promise`<`void`>
257257

258-
*Defined in [analytics.ts:225](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L225)*
258+
*Defined in [analytics.ts:233](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L233)*
259259

260260
Record the screens or views your users see.
261261

@@ -278,7 +278,7 @@ ___
278278

279279
**setup**(writeKey: *`string`*, configuration?: *[Configuration](../interfaces/analytics.configuration.md)*): `Promise`<`void`>
280280

281-
*Defined in [analytics.ts:188](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L188)*
281+
*Defined in [analytics.ts:196](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L196)*
282282

283283
Setup the Analytics module. All calls made before are queued and only executed if the configuration was successful.
284284

@@ -308,7 +308,7 @@ ___
308308

309309
**track**(event: *`string`*, properties?: *[JsonMap]()*, options?: *[Options]()*): `Promise`<`void`>
310310

311-
*Defined in [analytics.ts:207](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L207)*
311+
*Defined in [analytics.ts:215](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L215)*
312312

313313
Record the actions your users perform.
314314

@@ -331,7 +331,7 @@ ___
331331

332332
**useNativeConfiguration**(): `this`
333333

334-
*Defined in [analytics.ts:161](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L161)*
334+
*Defined in [analytics.ts:169](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L169)*
335335

336336
Use the native configuration.
337337

packages/core/docs/interfaces/analytics.configuration.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
* [android](analytics.configuration.md#android)
1414
* [debug](analytics.configuration.md#debug)
15+
* [defaultProjectSettings](analytics.configuration.md#defaultprojectsettings)
1516
* [flushAt](analytics.configuration.md#flushat)
1617
* [ios](analytics.configuration.md#ios)
1718
* [recordScreenViews](analytics.configuration.md#recordscreenviews)
@@ -29,7 +30,7 @@
2930

3031
**● android**: *`undefined` \| `object`*
3132

32-
*Defined in [analytics.ts:69](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L69)*
33+
*Defined in [analytics.ts:77](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L77)*
3334

3435
Android specific settings.
3536

@@ -42,14 +43,25 @@ ___
4243

4344
*Defined in [analytics.ts:38](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L38)*
4445

46+
___
47+
<a id="defaultprojectsettings"></a>
48+
49+
### `<Optional>` defaultProjectSettings
50+
51+
**● defaultProjectSettings**: *`undefined` \| `object`*
52+
53+
*Defined in [analytics.ts:46](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L46)*
54+
55+
Default project settings to use, if Segment.com cannot be reached. An example configuration can be found here, using your write key: [](https://cdn-settings.segment.com/v1/projects/YOUR_WRITE_KEY/settings)[https://cdn-settings.segment.com/v1/projects/YOUR\_WRITE\_KEY/settings](https://cdn-settings.segment.com/v1/projects/YOUR_WRITE_KEY/settings)
56+
4557
___
4658
<a id="flushat"></a>
4759

4860
### `<Optional>` flushAt
4961

5062
**● flushAt**: *`undefined` \| `number`*
5163

52-
*Defined in [analytics.ts:46](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L46)*
64+
*Defined in [analytics.ts:54](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L54)*
5365

5466
The number of queued events that the analytics client should flush at. Setting this to `1` will not queue any events and will use more battery.
5567

@@ -62,7 +74,7 @@ ___
6274

6375
**● ios**: *`undefined` \| `object`*
6476

65-
*Defined in [analytics.ts:51](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L51)*
77+
*Defined in [analytics.ts:59](https://github.com/segmentio/analytics-react-native/blob/master/packages/core/src/analytics.ts#L59)*
6678

6779
iOS specific settings.
6880

packages/core/ios/RNAnalytics/RNAnalytics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RNAnalytics
44
//
55
// Created by fathy on 05/08/2018.
6-
// Copyright © 2018 Segment.io, Inc. All rights reserved.
6+
// Copyright © 2020 Segment.io, Inc. All rights reserved.
77
//
88

99
#if __has_include("RCTBridgeModule.h")

packages/core/ios/RNAnalytics/RNAnalytics.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ +(void)initialize {
6161
config.trackAttributionData = [options[@"trackAttributionData"] boolValue];
6262
config.flushAt = [options[@"flushAt"] integerValue];
6363
config.enableAdvertisingTracking = [options[@"ios"][@"trackAdvertising"] boolValue];
64+
config.defaultSettings = options[@"defaultProjectSettings"];
6465

6566
for(id factory in RNAnalyticsIntegrations) {
6667
[config use:factory];

packages/core/src/__tests__/configuration.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ it('uses the default configuration', async () => {
1515
expect(await configure(writeKey, {})).toEqual(
1616
withIntegrity({
1717
debug: false,
18+
defaultProjectSettings: {},
1819
flushAt: 20,
1920
recordScreenViews: false,
2021
trackAppLifecycleEvents: false,
@@ -36,6 +37,13 @@ it('uses the default configuration', async () => {
3637
it('produces a valid configuration', async () => {
3738
const config = await configure(writeKey, {
3839
debug: true,
40+
defaultProjectSettings: {
41+
integrations: {
42+
Adjust: {
43+
appToken: '13213'
44+
}
45+
}
46+
},
3947
flushAt: 42,
4048
recordScreenViews: true,
4149
trackAppLifecycleEvents: true,
@@ -54,6 +62,13 @@ it('produces a valid configuration', async () => {
5462
expect(config).toEqual(
5563
withIntegrity({
5664
debug: true,
65+
defaultProjectSettings: {
66+
integrations: {
67+
Adjust: {
68+
appToken: '13213'
69+
}
70+
}
71+
},
5772
flushAt: 42,
5873
recordScreenViews: true,
5974
trackAppLifecycleEvents: true,

0 commit comments

Comments
 (0)