@capgo/capacitor-rudderstack 8.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapgoCapacitorRudderStack.podspec +19 -0
- package/LICENSE +373 -0
- package/Package.swift +30 -0
- package/README.md +390 -0
- package/android/build.gradle +182 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/app/capgo/rudderstack/RudderStackBridge.java +256 -0
- package/android/src/main/java/app/capgo/rudderstack/RudderStackPlugin.java +205 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +525 -0
- package/dist/esm/definitions.d.ts +154 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +211 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +63 -0
- package/dist/esm/web.js +69 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +283 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +286 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/RudderStackPlugin/RudderStackBridge.swift +244 -0
- package/ios/Sources/RudderStackPlugin/RudderStackPlugin.swift +210 -0
- package/ios/Tests/RudderStackPluginTests/RudderStackPluginTests.swift +8 -0
- package/package.json +94 -0
package/README.md
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
# @capgo/capacitor-rudderstack
|
|
2
|
+
<a href="https://capgo.app/"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-rudderstack" alt="Capgo - Instant updates for Capacitor" /></a>
|
|
3
|
+
|
|
4
|
+
<div align="center">
|
|
5
|
+
<h2><a href="https://capgo.app/?ref=plugin_rudderstack"> ➡️ Get Instant updates for your App with Capgo</a></h2>
|
|
6
|
+
<h2><a href="https://capgo.app/consulting/?ref=plugin_rudderstack"> Missing a feature? We’ll build the plugin for you 💪</a></h2>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
Capacitor plugin for RudderStack analytics and event tracking.
|
|
10
|
+
|
|
11
|
+
This package is a Capacitor port of [rudder-sdk-cordova](https://github.com/rudderlabs/rudder-sdk-cordova/tree/develop) with native Android and iOS bridges built for Capacitor 8.
|
|
12
|
+
|
|
13
|
+
## Documentation
|
|
14
|
+
|
|
15
|
+
The most complete doc is available here: https://capgo.app/docs/plugins/rudderstack/
|
|
16
|
+
|
|
17
|
+
## Compatibility
|
|
18
|
+
|
|
19
|
+
| Plugin version | Capacitor compatibility | Maintained |
|
|
20
|
+
| -------------- | ----------------------- | ---------- |
|
|
21
|
+
| v8.\*.\* | v8.\*.\* | ✅ |
|
|
22
|
+
| v7.\*.\* | v7.\*.\* | On demand |
|
|
23
|
+
| v6.\*.\* | v6.\*.\* | ❌ |
|
|
24
|
+
|
|
25
|
+
> **Note:** The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation. Only the latest major version is actively maintained.
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun add @capgo/capacitor-rudderstack
|
|
31
|
+
bunx cap sync
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { RudderStack } from '@capgo/capacitor-rudderstack';
|
|
38
|
+
|
|
39
|
+
await RudderStack.initialize('YOUR_WRITE_KEY', {
|
|
40
|
+
dataPlaneUrl: 'https://your-dataplane.rudderstack.com',
|
|
41
|
+
trackLifecycleEvents: true,
|
|
42
|
+
logLevel: RudderStack.LogLevel.INFO,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
await RudderStack.identify('user_123', {
|
|
46
|
+
email: 'user@example.com',
|
|
47
|
+
plan: 'pro',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await RudderStack.track('Checkout Started', {
|
|
51
|
+
value: 49,
|
|
52
|
+
currency: 'EUR',
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The API intentionally follows the Cordova plugin shape so existing Rudder Cordova integrations can migrate with minimal call-site changes.
|
|
57
|
+
|
|
58
|
+
## Behavior
|
|
59
|
+
|
|
60
|
+
- Android uses the RudderStack Android SDK and exposes the Cordova-compatible analytics surface through a Capacitor bridge.
|
|
61
|
+
- iOS uses the RudderStack iOS SDK with a Swift bridge that matches the same public API.
|
|
62
|
+
- Web is a lightweight compatibility implementation intended for development and API parity. It does not send events to RudderStack.
|
|
63
|
+
- `config.factories` from the Cordova plugin is currently ignored. Native destination factory companion plugins are not part of this first Capacitor port.
|
|
64
|
+
|
|
65
|
+
## API
|
|
66
|
+
|
|
67
|
+
<docgen-index>
|
|
68
|
+
|
|
69
|
+
* [`initialize(...)`](#initialize)
|
|
70
|
+
* [`identify(...)`](#identify)
|
|
71
|
+
* [`group(...)`](#group)
|
|
72
|
+
* [`track(...)`](#track)
|
|
73
|
+
* [`screen(...)`](#screen)
|
|
74
|
+
* [`alias(...)`](#alias)
|
|
75
|
+
* [`reset()`](#reset)
|
|
76
|
+
* [`flush()`](#flush)
|
|
77
|
+
* [`putDeviceToken(...)`](#putdevicetoken)
|
|
78
|
+
* [`setAdvertisingId(...)`](#setadvertisingid)
|
|
79
|
+
* [`putAdvertisingId(...)`](#putadvertisingid)
|
|
80
|
+
* [`setAnonymousId(...)`](#setanonymousid)
|
|
81
|
+
* [`putAnonymousId(...)`](#putanonymousid)
|
|
82
|
+
* [`optOut(...)`](#optout)
|
|
83
|
+
* [`getPluginVersion()`](#getpluginversion)
|
|
84
|
+
* [Interfaces](#interfaces)
|
|
85
|
+
* [Type Aliases](#type-aliases)
|
|
86
|
+
|
|
87
|
+
</docgen-index>
|
|
88
|
+
|
|
89
|
+
<docgen-api>
|
|
90
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
91
|
+
|
|
92
|
+
Capacitor API that mirrors the public surface of `rudder-sdk-cordova`.
|
|
93
|
+
|
|
94
|
+
### initialize(...)
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
initialize(writeKey: string, config?: RudderConfiguration | RudderOptions | undefined, options?: RudderOptions | undefined) => Promise<void>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Initializes the RudderStack client.
|
|
101
|
+
|
|
102
|
+
The method keeps the Cordova signature, so the second argument may be either a config object or
|
|
103
|
+
a Rudder options object.
|
|
104
|
+
|
|
105
|
+
| Param | Type |
|
|
106
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
107
|
+
| **`writeKey`** | <code>string</code> |
|
|
108
|
+
| **`config`** | <code><a href="#rudderconfiguration">RudderConfiguration</a> \| <a href="#rudderoptions">RudderOptions</a></code> |
|
|
109
|
+
| **`options`** | <code><a href="#rudderoptions">RudderOptions</a></code> |
|
|
110
|
+
|
|
111
|
+
--------------------
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
### identify(...)
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
identify(userId: string, traits?: RudderOptions | RudderTraits | undefined, options?: RudderOptions | undefined) => Promise<void>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Sends an identify call for the provided user id.
|
|
121
|
+
|
|
122
|
+
| Param | Type |
|
|
123
|
+
| ------------- | --------------------------------------------------------------------------------------------------- |
|
|
124
|
+
| **`userId`** | <code>string</code> |
|
|
125
|
+
| **`traits`** | <code><a href="#rudderoptions">RudderOptions</a> \| <a href="#ruddertraits">RudderTraits</a></code> |
|
|
126
|
+
| **`options`** | <code><a href="#rudderoptions">RudderOptions</a></code> |
|
|
127
|
+
|
|
128
|
+
--------------------
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
### group(...)
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
group(groupId: string, groupTraits?: RudderOptions | RudderTraits | undefined, options?: RudderOptions | undefined) => Promise<void>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Sends a group call for the provided group id.
|
|
138
|
+
|
|
139
|
+
| Param | Type |
|
|
140
|
+
| ----------------- | --------------------------------------------------------------------------------------------------- |
|
|
141
|
+
| **`groupId`** | <code>string</code> |
|
|
142
|
+
| **`groupTraits`** | <code><a href="#rudderoptions">RudderOptions</a> \| <a href="#ruddertraits">RudderTraits</a></code> |
|
|
143
|
+
| **`options`** | <code><a href="#rudderoptions">RudderOptions</a></code> |
|
|
144
|
+
|
|
145
|
+
--------------------
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### track(...)
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
track(eventName: string, properties?: RudderOptions | RudderProperties | undefined, options?: RudderOptions | undefined) => Promise<void>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Sends a track call for the provided event name.
|
|
155
|
+
|
|
156
|
+
| Param | Type |
|
|
157
|
+
| ---------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
158
|
+
| **`eventName`** | <code>string</code> |
|
|
159
|
+
| **`properties`** | <code><a href="#rudderoptions">RudderOptions</a> \| <a href="#rudderproperties">RudderProperties</a></code> |
|
|
160
|
+
| **`options`** | <code><a href="#rudderoptions">RudderOptions</a></code> |
|
|
161
|
+
|
|
162
|
+
--------------------
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
### screen(...)
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
screen(screenName: string, properties?: RudderOptions | RudderProperties | undefined, options?: RudderOptions | undefined) => Promise<void>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Sends a screen call for the provided screen name.
|
|
172
|
+
|
|
173
|
+
| Param | Type |
|
|
174
|
+
| ---------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
175
|
+
| **`screenName`** | <code>string</code> |
|
|
176
|
+
| **`properties`** | <code><a href="#rudderoptions">RudderOptions</a> \| <a href="#rudderproperties">RudderProperties</a></code> |
|
|
177
|
+
| **`options`** | <code><a href="#rudderoptions">RudderOptions</a></code> |
|
|
178
|
+
|
|
179
|
+
--------------------
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
### alias(...)
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
alias(newId: string, options?: RudderOptions | undefined) => Promise<void>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Aliases the current user to a new identifier.
|
|
189
|
+
|
|
190
|
+
| Param | Type |
|
|
191
|
+
| ------------- | ------------------------------------------------------- |
|
|
192
|
+
| **`newId`** | <code>string</code> |
|
|
193
|
+
| **`options`** | <code><a href="#rudderoptions">RudderOptions</a></code> |
|
|
194
|
+
|
|
195
|
+
--------------------
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
### reset()
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
reset() => Promise<void>
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Resets the current RudderStack identity state.
|
|
205
|
+
|
|
206
|
+
--------------------
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
### flush()
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
flush() => Promise<void>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Flushes queued events immediately.
|
|
216
|
+
|
|
217
|
+
--------------------
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
### putDeviceToken(...)
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
putDeviceToken(deviceToken: string) => Promise<void>
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Sets the push token that RudderStack forwards to supported destinations.
|
|
227
|
+
|
|
228
|
+
| Param | Type |
|
|
229
|
+
| ----------------- | ------------------- |
|
|
230
|
+
| **`deviceToken`** | <code>string</code> |
|
|
231
|
+
|
|
232
|
+
--------------------
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
### setAdvertisingId(...)
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
setAdvertisingId(advertisingId: string) => Promise<void>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
| Param | Type |
|
|
242
|
+
| ------------------- | ------------------- |
|
|
243
|
+
| **`advertisingId`** | <code>string</code> |
|
|
244
|
+
|
|
245
|
+
--------------------
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
### putAdvertisingId(...)
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
putAdvertisingId(advertisingId: string) => Promise<void>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Sets a custom advertising id value.
|
|
255
|
+
|
|
256
|
+
| Param | Type |
|
|
257
|
+
| ------------------- | ------------------- |
|
|
258
|
+
| **`advertisingId`** | <code>string</code> |
|
|
259
|
+
|
|
260
|
+
--------------------
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
### setAnonymousId(...)
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
setAnonymousId(anonymousId: string) => Promise<void>
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
| Param | Type |
|
|
270
|
+
| ----------------- | ------------------- |
|
|
271
|
+
| **`anonymousId`** | <code>string</code> |
|
|
272
|
+
|
|
273
|
+
--------------------
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
### putAnonymousId(...)
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
putAnonymousId(anonymousId: string) => Promise<void>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Sets a custom anonymous id value.
|
|
283
|
+
|
|
284
|
+
| Param | Type |
|
|
285
|
+
| ----------------- | ------------------- |
|
|
286
|
+
| **`anonymousId`** | <code>string</code> |
|
|
287
|
+
|
|
288
|
+
--------------------
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
### optOut(...)
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
optOut(optOut: boolean) => Promise<void>
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Toggles RudderStack tracking opt-out.
|
|
298
|
+
|
|
299
|
+
| Param | Type |
|
|
300
|
+
| ------------ | -------------------- |
|
|
301
|
+
| **`optOut`** | <code>boolean</code> |
|
|
302
|
+
|
|
303
|
+
--------------------
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
### getPluginVersion()
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
getPluginVersion() => Promise<PluginVersionResult>
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Returns the plugin version marker from the native implementation.
|
|
313
|
+
|
|
314
|
+
**Returns:** <code>Promise<<a href="#pluginversionresult">PluginVersionResult</a>></code>
|
|
315
|
+
|
|
316
|
+
--------------------
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
### Interfaces
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
#### RudderConfiguration
|
|
323
|
+
|
|
324
|
+
Supported configuration keys for the underlying RudderStack native SDKs.
|
|
325
|
+
|
|
326
|
+
| Prop | Type | Description |
|
|
327
|
+
| --------------------------- | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
328
|
+
| **`dataPlaneUrl`** | <code>string</code> | RudderStack data plane URL. |
|
|
329
|
+
| **`flushQueueSize`** | <code>number</code> | Number of events to batch before a flush. |
|
|
330
|
+
| **`dbCountThreshold`** | <code>number</code> | Database row threshold that triggers pruning on Android and iOS. |
|
|
331
|
+
| **`configRefreshInterval`** | <code>number</code> | Server config refresh interval in hours. |
|
|
332
|
+
| **`logLevel`** | <code><a href="#rudderloglevelvalue">RudderLogLevelValue</a></code> | RudderStack log verbosity. |
|
|
333
|
+
| **`sleepTimeOut`** | <code>number</code> | Sleep timeout / sleep count used by the native SDK. |
|
|
334
|
+
| **`autoCollectAdvertId`** | <code>boolean</code> | Android only. Lets the native SDK collect the advertising identifier automatically. |
|
|
335
|
+
| **`trackLifecycleEvents`** | <code>boolean</code> | Tracks `Application Installed`, `Application Updated`, and `Application Opened` automatically. |
|
|
336
|
+
| **`controlPlaneUrl`** | <code>string</code> | RudderStack control plane URL. |
|
|
337
|
+
| **`recordScreenViews`** | <code>boolean</code> | Enables automatic screen tracking where supported by the native SDK. |
|
|
338
|
+
| **`factories`** | <code>any[]</code> | Ignored in this Capacitor port. The Cordova SDK uses this field to bootstrap native destination factories from companion plugins. Those extension packages are not implemented in this first Capacitor release. |
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
#### RudderOptions
|
|
342
|
+
|
|
343
|
+
RudderStack per-call options.
|
|
344
|
+
|
|
345
|
+
| Prop | Type | Description |
|
|
346
|
+
| ------------------ | ---------------------------------------------------------------- | ------------------------------------------------------- |
|
|
347
|
+
| **`externalIds`** | <code><a href="#record">Record</a><string, string></code> | External identifiers forwarded with the event. |
|
|
348
|
+
| **`integrations`** | <code><a href="#record">Record</a><string, boolean></code> | Destination enablement flags keyed by integration name. |
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
#### PluginVersionResult
|
|
352
|
+
|
|
353
|
+
Plugin version payload.
|
|
354
|
+
|
|
355
|
+
| Prop | Type | Description |
|
|
356
|
+
| ------------- | ------------------- | ----------------------------------------------------------- |
|
|
357
|
+
| **`version`** | <code>string</code> | Version identifier returned by the platform implementation. |
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
### Type Aliases
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
#### RudderLogLevelValue
|
|
364
|
+
|
|
365
|
+
RudderStack log level values exposed for migration convenience.
|
|
366
|
+
|
|
367
|
+
<code>0 | 1 | 2 | 3 | 4 | 5</code>
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
#### Record
|
|
371
|
+
|
|
372
|
+
Construct a type with a set of properties K of type T
|
|
373
|
+
|
|
374
|
+
<code>{
|
|
375
|
[P in K]: T;
|
|
1
376
|
}</code>
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
#### RudderTraits
|
|
380
|
+
|
|
381
|
+
Traits payload accepted by `identify` and `group`.
|
|
382
|
+
|
|
383
|
+
<code><a href="#record">Record</a><string, any></code>
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
#### RudderProperties
|
|
387
|
+
|
|
388
|
+
Properties payload accepted by `track` and `screen`.
|
|
389
|
+
|
|
390
|
+
<code><a href="#record">Record</a><string, any></code>
|
|
391
|
+
|
|
392
|
+
</docgen-api>
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import groovy.json.JsonSlurper
|
|
2
|
+
|
|
3
|
+
import java.nio.file.FileVisitResult
|
|
4
|
+
import java.nio.file.Files
|
|
5
|
+
import java.nio.file.Path
|
|
6
|
+
import java.nio.file.SimpleFileVisitor
|
|
7
|
+
import java.nio.file.attribute.BasicFileAttributes
|
|
8
|
+
|
|
9
|
+
String getPackageJsonPath() {
|
|
10
|
+
String envPath = findProperty("RUDDERSTACK_PACKAGE_JSON_PATH") as String
|
|
11
|
+
if (envPath) {
|
|
12
|
+
logger.lifecycle("package.json path from RUDDERSTACK_PACKAGE_JSON_PATH: $envPath")
|
|
13
|
+
return envPath
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
def possiblePackageJsonPaths = [
|
|
17
|
+
"${projectDir.parentFile}/package.json",
|
|
18
|
+
"${buildDir.parentFile.parentFile}/package.json",
|
|
19
|
+
"${rootDir.parentFile}/node_modules/@capgo/capacitor-rudderstack/package.json",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
for (possiblePath in possiblePackageJsonPaths) {
|
|
23
|
+
File possibleFile = file(possiblePath)
|
|
24
|
+
if (possibleFile.exists()) {
|
|
25
|
+
logger.lifecycle("Found package.json at: ${possibleFile.absolutePath}")
|
|
26
|
+
return possibleFile.absolutePath
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
logger.lifecycle("Did not locate package.json in any of possiblePackageJsonPaths and RUDDERSTACK_PACKAGE_JSON_PATH is not specified.")
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static def findNodeModulesDir(File currentDir) {
|
|
35
|
+
def dir = currentDir
|
|
36
|
+
while (dir != null) {
|
|
37
|
+
def nodeModulesDir = new File(dir, 'node_modules')
|
|
38
|
+
if (nodeModulesDir.exists()) {
|
|
39
|
+
return nodeModulesDir
|
|
40
|
+
}
|
|
41
|
+
dir = dir.parentFile
|
|
42
|
+
}
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
def findPackageJsonInDep(String packageName) {
|
|
47
|
+
def nodeModulesDir = findNodeModulesDir(project.rootDir)
|
|
48
|
+
if (nodeModulesDir == null) {
|
|
49
|
+
logger.lifecycle("node_modules directory not found in any parent directories.")
|
|
50
|
+
return null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
def json = null
|
|
54
|
+
|
|
55
|
+
def walker = new SimpleFileVisitor<Path>() {
|
|
56
|
+
@Override
|
|
57
|
+
FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
|
58
|
+
if (file.toAbsolutePath().endsWith("@capgo/capacitor-rudderstack/package.json")) {
|
|
59
|
+
try {
|
|
60
|
+
def content = new JsonSlurper().parseText(file.toFile().text)
|
|
61
|
+
if (content.name == packageName) {
|
|
62
|
+
logger.lifecycle("Found package.json at: ${file.toAbsolutePath()}")
|
|
63
|
+
json = content
|
|
64
|
+
return FileVisitResult.TERMINATE
|
|
65
|
+
}
|
|
66
|
+
} catch (Exception e) {
|
|
67
|
+
logger.lifecycle("Error parsing JSON in file: ${file.toAbsolutePath().toString()}\n${e.message}\n\t")
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return FileVisitResult.CONTINUE
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
while (json == null && nodeModulesDir != null) {
|
|
75
|
+
Files.walkFileTree(nodeModulesDir.toPath(), walker)
|
|
76
|
+
nodeModulesDir = findNodeModulesDir(nodeModulesDir.parentFile.parentFile)
|
|
77
|
+
}
|
|
78
|
+
return json
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
def getPackageJson() {
|
|
82
|
+
String packageJsonPath = getPackageJsonPath()
|
|
83
|
+
File inputFile = packageJsonPath ? new File(packageJsonPath) : null
|
|
84
|
+
|
|
85
|
+
if (inputFile?.exists()) {
|
|
86
|
+
try {
|
|
87
|
+
return new JsonSlurper().parseText(inputFile.getText('UTF-8'))
|
|
88
|
+
} catch (Exception e) {
|
|
89
|
+
logger.error("Failed to parse package.json at: ${inputFile.absolutePath}", e)
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
logger.lifecycle("Searching for package.json recursively in node_modules directories...")
|
|
93
|
+
def foundJson = findPackageJsonInDep("@capgo/capacitor-rudderstack")
|
|
94
|
+
if (foundJson) {
|
|
95
|
+
return foundJson
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
logger.error("The plugin package.json could not be loaded properly; @capgo/capacitor-rudderstack may not function as expected.")
|
|
100
|
+
return null
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
ext {
|
|
104
|
+
packageJson = getPackageJson()
|
|
105
|
+
|
|
106
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
107
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
108
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
109
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
110
|
+
lifecycleVersion = project.hasProperty('androidxLifecycleVersion') ? rootProject.ext.androidxLifecycleVersion : '2.8.7'
|
|
111
|
+
workVersion = project.hasProperty('androidxWorkVersion') ? rootProject.ext.androidxWorkVersion : '2.10.2'
|
|
112
|
+
rudderSdkVersion = packageJson?.androidSdkVersion ?: '1.27.2'
|
|
113
|
+
pluginVersion = packageJson?.version ?: '8.0.0'
|
|
114
|
+
pluginBuildVersion = packageJson?.buildNumber ?: '1'
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
buildscript {
|
|
118
|
+
repositories {
|
|
119
|
+
google()
|
|
120
|
+
mavenCentral()
|
|
121
|
+
}
|
|
122
|
+
dependencies {
|
|
123
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
124
|
+
classpath 'org.codehaus.groovy:groovy-json:3.0.9'
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
apply plugin: 'com.android.library'
|
|
129
|
+
|
|
130
|
+
android {
|
|
131
|
+
namespace = "app.capgo.rudderstack"
|
|
132
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
133
|
+
|
|
134
|
+
defaultConfig {
|
|
135
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
136
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
137
|
+
versionCode Integer.parseInt(pluginBuildVersion)
|
|
138
|
+
versionName "$pluginVersion"
|
|
139
|
+
buildConfigField "int", "VERSION_CODE", pluginBuildVersion
|
|
140
|
+
buildConfigField "String", "VERSION_NAME", "\"$pluginVersion\""
|
|
141
|
+
buildConfigField "String", "RUDDER_SDK_VERSION", "\"$rudderSdkVersion\""
|
|
142
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
buildTypes {
|
|
146
|
+
release {
|
|
147
|
+
minifyEnabled false
|
|
148
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
lintOptions {
|
|
153
|
+
abortOnError = false
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
compileOptions {
|
|
157
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
158
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
buildFeatures {
|
|
162
|
+
buildConfig = true
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
repositories {
|
|
167
|
+
google()
|
|
168
|
+
mavenCentral()
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
dependencies {
|
|
172
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
173
|
+
implementation project(':capacitor-android')
|
|
174
|
+
annotationProcessor project(':capacitor-android')
|
|
175
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
176
|
+
implementation "androidx.lifecycle:lifecycle-process:$lifecycleVersion"
|
|
177
|
+
implementation "androidx.work:work-runtime:$workVersion"
|
|
178
|
+
implementation "com.rudderstack.android.sdk:core:$rudderSdkVersion"
|
|
179
|
+
testImplementation "junit:junit:$junitVersion"
|
|
180
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
181
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
182
|
+
}
|