-
Notifications
You must be signed in to change notification settings - Fork 69
feat: Migrate Branch 5 kit #666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
55fb6b3
0e69e1f
ac35bdd
61fa56e
9e1fc8a
0545881
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ internal object CustomDataParser { | |
| try { | ||
| if (value != null) parseValueGuarded(value) else null | ||
| } catch (e: Exception) { | ||
| Log.e(LogTag("pParticle"), "Unable to parse value: $value") | ||
| Log.e(LogTag("pParticle"), "Unable to parse custom data value") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is intentional. MobSF flagged this as android_kotlin_logging because $value can contain user-provided data |
||
| value | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ## Branch Kit Integration | ||
|
|
||
| This repository contains the [Branch](https://www.branch.io/) integration for the [mParticle Android SDK](https://github.com/mParticle/mparticle-android-sdk). | ||
|
|
||
| ### Adding the integration | ||
|
|
||
| 1. Add the kit dependency to your app's build.gradle: | ||
|
|
||
| ```groovy | ||
| dependencies { | ||
| implementation 'com.mparticle:android-branch-kit:5+' | ||
| } | ||
| ``` | ||
| 2. Follow the mParticle Android SDK [quick-start](https://github.com/mParticle/mparticle-android-sdk), then rebuild and launch your app, and verify that you see `"Branch Metrics detected"` in the output of `adb logcat`. | ||
| 3. Reference mParticle's integration docs below to enable the integration. | ||
|
|
||
| ### Documentation | ||
|
|
||
| [Branch integration](https://docs.mparticle.com/integrations/branch-metrics/event/) | ||
|
|
||
| ### License | ||
|
|
||
| [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| *.iml | ||
| .gradle | ||
| /local.properties | ||
| /.idea/workspace.xml | ||
| /.idea/libraries | ||
| .DS_Store | ||
| /build | ||
| /captures | ||
| .externalNativeBuild |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ##mParticle-Branch Example | ||
|
|
||
| ###Overview | ||
|
|
||
| This sample app demonstrates: | ||
|
|
||
| • How to use the mParticle and Branch in a simple Android application. | ||
|
|
||
| • How to create and share Branch links in your app. | ||
|
|
||
| • How to Branch deep links are handled in an app when using branch with mParticle. | ||
|
|
||
| • How event tracking is handled in mParticle and Branch. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| apply plugin: 'com.android.application' | ||
|
|
||
| android { | ||
| compileSdk = 34 | ||
| buildToolsVersion "27.0.3" | ||
| defaultConfig { | ||
| applicationId "com.mparticle.branchsample" | ||
| minSdk = 25 | ||
| targetSdk = 33 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
| testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
| } | ||
| buildTypes { | ||
| release { | ||
| minifyEnabled false | ||
| proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
| } | ||
| } | ||
| packagingOptions { | ||
| exclude 'META-INF/proguard/androidx-annotations.pro' | ||
| exclude 'META-INF/versions/9/module-info.class' | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
| implementation 'androidx.appcompat:appcompat:1.6.1' | ||
| implementation 'com.google.android.material:material:1.8.0' | ||
| implementation 'com.android.installreferrer:installreferrer:2.2' | ||
|
|
||
| // Local project dependency | ||
| api project(':local-mParticle-Branch-kit') | ||
|
|
||
| // Uncomment below to use published version instead | ||
| // implementation 'com.mparticle:android-branch-kit:5+' | ||
|
|
||
| testImplementation 'junit:junit:4.13.2' | ||
|
|
||
| androidTestImplementation('androidx.test.espresso:espresso-core:3.5.1', { | ||
| exclude group: 'androidx.test', module: 'runner' | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Add project specific ProGuard rules here. | ||
| # By default, the flags in this file are appended to flags specified | ||
| # You can edit the include path and order by changing the proguardFiles | ||
| # directive in build.gradle. | ||
| # | ||
| # For more details, see | ||
| # http://developer.android.com/guide/developing/tools/proguard.html | ||
|
|
||
| # Add any project specific keep options here: | ||
|
|
||
| # If your project uses WebView with JS, uncomment the following | ||
| # and specify the fully qualified class name to the JavaScript interface | ||
| # class: | ||
| #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| # public *; | ||
| #} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.mparticle.branchsample; | ||
|
|
||
| import android.content.Context; | ||
| import android.support.test.InstrumentationRegistry; | ||
| import android.support.test.runner.AndroidJUnit4; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| /** | ||
| * Instrumentation test, which will execute on an Android device. | ||
| * | ||
| * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
| */ | ||
| @RunWith(AndroidJUnit4.class) | ||
| public class ExampleInstrumentedTest { | ||
| @Test | ||
| public void useAppContext() throws Exception { | ||
| // Context of the app under test. | ||
| Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
|
||
| assertEquals("com.mparticle.branchsample", appContext.getPackageName()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest package="com.mparticle.branchsample" | ||
| xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| <application | ||
| android:name=".SampleApplication" | ||
| android:allowBackup="true" | ||
| android:icon="@drawable/app_icon" | ||
| android:label="@string/app_name" | ||
| android:supportsRtl="true" | ||
| android:theme="@style/AppTheme"> | ||
|
|
||
| <activity | ||
| android:name=".activities.SplashActivity" | ||
| android:exported="true" | ||
| android:label="@string/app_name" | ||
| android:launchMode="singleTask" | ||
| android:screenOrientation="portrait" | ||
| android:windowSoftInputMode="stateHidden"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN"/> | ||
| <category android:name="android.intent.category.LAUNCHER"/> | ||
| </intent-filter> | ||
|
|
||
| <intent-filter android:autoVerify="true"> | ||
| <action android:name="android.intent.action.VIEW" /> | ||
| <category android:name="android.intent.category.DEFAULT" /> | ||
| <category android:name="android.intent.category.BROWSABLE" /> | ||
| <data android:scheme="https" android:host="mp-fortune.app.link" /> <!-- Custom App link - Live --> | ||
| <data android:scheme="https" android:host="mp-fortune.test-app.link" /> | ||
| </intent-filter> | ||
| </activity> | ||
|
|
||
| <activity | ||
| android:name=".activities.HomeActivity" | ||
| android:exported="true" | ||
| android:label="@string/app_name" | ||
| android:launchMode="singleTask" | ||
| android:screenOrientation="portrait"/> | ||
| </application> | ||
|
|
||
| </manifest> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package com.mparticle.branchsample; | ||
|
|
||
| import android.app.Application; | ||
|
|
||
| import com.mparticle.AttributionError; | ||
| import com.mparticle.AttributionListener; | ||
| import com.mparticle.AttributionResult; | ||
| import com.mparticle.MParticle; | ||
| import com.mparticle.MParticleOptions; | ||
|
|
||
| import org.json.JSONObject; | ||
|
|
||
| import io.branch.referral.Branch; | ||
|
|
||
| public class SampleApplication extends Application implements AttributionListener { | ||
|
Check warning on line 15 in kits/branch/branch-5/SampleApplication/app/src/main/java/com/mparticle/branchsample/SampleApplication.java
|
||
| private IBranchEvents branchEventCallback; | ||
| private static SampleApplication instance; | ||
|
|
||
| @Override | ||
| public void onCreate() { | ||
| super.onCreate(); | ||
| instance = this; | ||
|
Check failure on line 22 in kits/branch/branch-5/SampleApplication/app/src/main/java/com/mparticle/branchsample/SampleApplication.java
|
||
| MParticleOptions options = MParticleOptions.builder(this) | ||
| .credentials("REPLACE_ME_WITH_API_KEY", "REPLACE_ME_WITH_API_SECRET") | ||
| .attributionListener(this) | ||
| //Set an instance of AttributionListener | ||
| //this instance will continually be called whenever | ||
| //there is new attribution/deep linking information. | ||
| //It is essentially equivalent to the Branch SDK's BranchReferralInitListener class | ||
| //that is passed to the Branch SDK's initSession() API. | ||
| .logLevel(MParticle.LogLevel.VERBOSE) | ||
| .build(); | ||
|
|
||
| MParticle.start(options); | ||
| } | ||
|
|
||
| public static void setBranchEventCallback(IBranchEvents branchEventCallback) { | ||
| instance.branchEventCallback = branchEventCallback; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * A few typical scenarios where this callback would be invoked: | ||
| * <p> | ||
| * (1) Base case: | ||
| * - User does not tap on a link, and then opens the app (either after a fresh install or not) | ||
| * - This block will be invoked with Branch Metrics' response indicating that this user did not tap on a link. | ||
| * <p> | ||
| * (2) Deferred deep link: | ||
| * - User without the app installed taps on a link | ||
| * - User is redirected from Branch Metrics to the App Store and installs the app | ||
| * - User opens the app | ||
| * - This block will be invoked with Branch Metrics' response containing the details of the link | ||
| * <p> | ||
| * (3) Deep link with app installed: | ||
| * - User with the app already installed taps on a link | ||
| * - Application opens directly to an Activity via a link click, mParticle forwards the launch URI etc to Branch | ||
| * - This callback will be invoked with Branch Metrics' response containing the details of the link | ||
| * <p> | ||
| * If the user navigates away from the app without killing it, this callback could be invoked several times: | ||
| * once for the initial launch, and then again each time the user taps on a link to re-open the app. | ||
| * | ||
| * <p> | ||
| * This method is equivalent to {@link io.branch.referral.Branch#initSession(Branch.BranchReferralInitListener)}. | ||
| * This will return deep links params if the app is opened by a link click otherwise a JSONObject with ""+clicked_branch_link = false". | ||
| * The below example shows how you can message this to your Activities listening for Branch deep link params. | ||
| * </p> | ||
| * | ||
| * @param attributionResult | ||
| **/ | ||
| @Override | ||
| public void onResult(AttributionResult attributionResult) { | ||
| //this will be invoked for | ||
| if (attributionResult.getServiceProviderId() == MParticle.ServiceProviders.BRANCH_METRICS) { | ||
| JSONObject params = attributionResult.getParameters(); | ||
| // The Branch SDK will return a response for all new session/app opens, even | ||
| // if the user did not click a branch link. | ||
| // The parameters supported by the Branch SDK are documented here: | ||
| // https://github.com/BranchMetrics/android-branch-deep-linking#branch-provided-data-parameters-in-initsession-callback | ||
| // For eg: | ||
| // if (params.optBoolean("+clicked_branch_link", false)) { | ||
|
Check warning on line 81 in kits/branch/branch-5/SampleApplication/app/src/main/java/com/mparticle/branchsample/SampleApplication.java
|
||
| // //handle the Branch link click | ||
| // } | ||
| if (branchEventCallback != null) { | ||
| branchEventCallback.onBranchInitialised(params); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onError(AttributionError attributionError) { | ||
| //if the Branch SDK returns an error, it will be surfaced here. | ||
| if (branchEventCallback != null) { | ||
| branchEventCallback.onBranchInitialised(new JSONObject()); | ||
| } | ||
| } | ||
|
|
||
| public interface IBranchEvents { | ||
| void onBranchInitialised(JSONObject params); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add just that kit's test app path to the ignore list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore-pathsin mobsfscan doesn't exclude manifest files from scanning — they're checked separately. So we need to keep theignore-rulesfor these three findings.