Skip to content

Commit 3341857

Browse files
authored
Mixpanel + Firebase Refactor (#43)
* refactor firebase destination * refactor mixpanel destination * cleanup dependency lists * update kotlin version * update readme * update circle config * resolve PR comments
1 parent 6d035be commit 3341857

File tree

9 files changed

+1625
-329
lines changed

9 files changed

+1625
-329
lines changed

.circleci/config.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ jobs:
1919
- ~/.gradle
2020
key: jars-{{ checksum "build.gradle" }}-{{ checksum "samples/kotlin-android-app/build.gradle" }}-{{ checksum "samples/java-android-app/build.gradle" }}
2121
- run:
22-
name: Run Tests
23-
command: ./gradlew lint test
22+
name: Run Core Tests
23+
command: ./gradlew core:test
24+
- run:
25+
name: Run Android Tests
26+
command: ./gradlew android:test
27+
- run:
28+
name: Run Sample Destination Tests
29+
command: ./gradlew samples:kotlin-android-app-destinations:test
2430
- run:
2531
name: Snyk
2632
command: curl -sL https://raw.githubusercontent.com/segmentio/snyk_helpers/master/initialization/snyk.sh | sh

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.4.10"
3+
ext.kotlin_version = "1.5.30"
44
ext.writeKey = "hAh3QxoRCsQsnyabTLMpWbpxoIN4O2mU"
55
repositories {
66
google()

samples/kotlin-android-app-destinations/README.md

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,17 @@
22
This is a sample android app that uses the `analytics-kotlin` library and the new `Plugins` concepts. It is meant to be simplistic, and easy to understand all the while showcasing the power of the analytics-kotlin library
33

44
## Plugins
5-
- Android AdvertisingId Plugin
6-
Using the `play-services-ads` library this plugin adds the `advertisingId` to all payloads (under the `context` key) going through the analytics timeline
5+
- [Amplitude Session](https://github.com/segmentio/analytics-kotlin/blob/master/samples/kotlin-android-app-destinations/src/main/java/com/segment/analytics/destinations/plugins/AmplitudeSession.kt)
6+
Sample plugin to enable users to enrich data for the Amplitude Actions destination
77

8-
- Android Record Screen Plugin
9-
Using the application lifecycle, this plugin automatically sends `Screen` events through the analytics timeline, on Activity start
8+
- [Firebase](https://github.com/segmentio/analytics-kotlin/blob/master/samples/kotlin-android-app-destinations/src/main/java/com/segment/analytics/destinations/plugins/FirebaseDestination.kt)
9+
Sample plugin to enable users to send data to the device-mode Firebase destination
1010

11-
- Consent Tracking
12-
Presents user with a dialog to consent to tracking. If consent is given, any queued events will be sent out to the analytics timeline. If consent is not given, all queued events and future events will be dropped
13-
** Note: You will have to switch to the `ConsentActivity` inside of AndroidManifest.xml to view this feature **
11+
- [Intercom](https://github.com/segmentio/analytics-kotlin/blob/master/samples/kotlin-android-app-destinations/src/main/java/com/segment/analytics/destinations/plugins/IntercomDestination.kt)
12+
Sample plugin to enable users to send data to the device-mode Intercom destination
1413

15-
- Webhook Plugin
16-
A destination plugin that allows you to send the event from the analytics timeline to a webhook of your choice. Ideal for debugging payloads in an internal network.
14+
- [Mixpanel](https://github.com/segmentio/analytics-kotlin/blob/master/samples/kotlin-android-app-destinations/src/main/java/com/segment/analytics/destinations/plugins/MixpanelDestination.kt)
15+
Sample plugin to enable users to send data to the device-mode Mixpanel destination
1716

18-
## Tracking Deep Links
19-
The sample app is configured to open links with the schema and hostname `https://segment-sample.com`
20-
21-
Here is how you can do it via adb
22-
```bash
23-
adb shell am start -W -a android.intent.action.VIEW -d "https://segment-sample.com?utm_source=cli\&utm_click=2" com.segment.analytics.next
24-
```
25-
26-
## FCM
27-
This project is setup to track push notification received and opened events. This code is strictly optional and must be customized as per your needs. The code here is only for demonstration purposes
28-
### Setup
29-
- Add your FCM project's `google-services.json` to this folder
30-
- Modify `MyFirebaseService.kt` to customize the notification displayed to the user.
31-
- Here is how to send a push notification using cURL [this uses the legacy api](https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-using-the-legacy-app-server-protocols)
32-
```bash
33-
curl --request POST \
34-
--url https://fcm.googleapis.com/fcm/send \
35-
--header 'Authorization: key=<SERVER_KEY>' \
36-
--header 'Content-Type: application/json' \
37-
--data '{
38-
"data": {
39-
"title": "Hello World"
40-
"content": "You have mail",
41-
},
42-
"to": "<FCM_TOKEN_FOR_DEVICE>"
43-
}'
44-
```
45-
46-
### How it works
47-
- We have 2 core changes
48-
- MyFirebaseService.kt
49-
The core component to handle FCM push messages. This is responsible for handling the incoming message and assigning the intents for the notification. It is also responsible for firing the `Push Notification Received` event.
50-
- PushNotificationTracking.kt
51-
The analytics plugin responsible for firing the "Push Notification Tapped" event. This is a lifecycle plugin that will be invoked for any Activity onCreate.
17+
- [Webhook Plugin](https://github.com/segmentio/analytics-kotlin/blob/master/samples/kotlin-android-app-destinations/src/main/java/com/segment/analytics/destinations/plugins/WebhookPlugin.kt)
18+
An after plugin that allows you to send the event from the analytics timeline to a webhook of your choice. Ideal for debugging payloads in an internal network.

samples/kotlin-android-app-destinations/build.gradle

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,55 +28,72 @@ android {
2828
}
2929
}
3030
compileOptions {
31+
coreLibraryDesugaringEnabled true
3132
sourceCompatibility JavaVersion.VERSION_1_8
3233
targetCompatibility JavaVersion.VERSION_1_8
3334
}
3435
kotlinOptions {
3536
jvmTarget = '1.8'
3637
}
3738
testOptions {
39+
unitTests.returnDefaultValues = true
40+
unitTests.includeAndroidResources = true
3841
unitTests.all {
3942
useJUnitPlatform()
4043
}
4144
}
4245
}
4346

4447
dependencies {
48+
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
4549

50+
implementation project(':android')
51+
implementation 'androidx.multidex:multidex:2.0.1'
52+
53+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
54+
implementation 'androidx.core:core-ktx:1.6.0'
55+
implementation 'androidx.appcompat:appcompat:1.3.1'
56+
implementation 'com.google.android.material:material:1.4.0'
57+
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
58+
59+
implementation 'androidx.lifecycle:lifecycle-process:2.3.1'
60+
implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
61+
}
62+
63+
// Partner Dependencies
64+
dependencies {
4665
// Mixpanel
4766
api 'com.mixpanel.android:mixpanel-android:5.8.7'
4867

4968
// Firebase
5069
implementation platform('com.google.firebase:firebase-bom:28.2.1')
51-
// Declare the dependency for the Analytics library
52-
// When using the BoM, you don't specify versions in Firebase library dependencies
5370
implementation 'com.google.firebase:firebase-analytics-ktx'
5471

5572
// Intercom
5673
implementation 'io.intercom.android:intercom-sdk-base:10.1.1'
5774
implementation 'io.intercom.android:intercom-sdk-fcm:10.1.1'
75+
}
5876

59-
implementation project(':android')
60-
61-
implementation 'androidx.multidex:multidex:2.0.1'
77+
// Test Dependencies
78+
dependencies {
79+
testImplementation 'junit:junit:4.+'
80+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
81+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
82+
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'
6283

63-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
64-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
84+
testImplementation 'io.mockk:mockk:1.10.6'
85+
testImplementation(platform("org.junit:junit-bom:5.7.2"))
86+
testImplementation("org.junit.jupiter:junit-jupiter")
6587

66-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
67-
implementation 'androidx.core:core-ktx:1.3.2'
68-
implementation 'androidx.appcompat:appcompat:1.2.0'
69-
implementation 'com.google.android.material:material:1.3.0'
70-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
88+
// Add Roboelectric dependencies.
89+
testImplementation 'org.robolectric:robolectric:4.5'
90+
testImplementation 'androidx.test:core:1.3.0'
7191

72-
implementation 'androidx.lifecycle:lifecycle-process:2.3.1'
73-
implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
92+
// Add JUnit4 legacy dependencies.
93+
testImplementation 'junit:junit:4.13.2'
94+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.7.0'
7495

75-
testImplementation 'io.mockk:mockk:1.10.6'
76-
testImplementation 'junit:junit:4.+'
77-
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'
78-
testImplementation platform("org.junit:junit-bom:5.7.2")
79-
testImplementation "org.junit.jupiter:junit-jupiter"
80-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
81-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
96+
// For JSON Object testing
97+
testImplementation 'org.json:json:20180813'
98+
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
8299
}

0 commit comments

Comments
 (0)