-
Notifications
You must be signed in to change notification settings - Fork 1
Feature - MPArticle Kotlin Integration #17
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
Open
EllingtonKirby
wants to merge
1
commit into
master
Choose a base branch
from
feature/mparticle_kotlin_integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| #Tue May 02 16:55:48 EDT 2017 | ||
| #Mon Sep 18 12:12:01 EDT 2017 | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| include ':simcoe' | ||
| include ':simcoe', ':simcoe-mparticle' | ||
|
Member
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. at the line |
||
| include ':simcoe-mixpanel' | ||
| include ':sample' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| apply plugin: 'com.android.library' | ||
| apply plugin: 'kotlin-android' | ||
|
|
||
| android { | ||
| compileSdkVersion rootProject.ext.compileSdkVersion | ||
| buildToolsVersion rootProject.ext.buildToolsVersion | ||
|
|
||
| defaultConfig { | ||
| minSdkVersion rootProject.ext.minSdkVersion | ||
| targetSdkVersion rootProject.ext.targetSdkVersion | ||
|
|
||
| versionCode Integer.parseInt(project.VERSION_CODE) | ||
| versionName project.VERSION_NAME | ||
|
|
||
| testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
| } | ||
| buildTypes { | ||
| release { | ||
| minifyEnabled false | ||
| proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
|
||
| api 'com.mparticle:android-core:4.16.2' | ||
| compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | ||
| compile project(path: ':simcoe') | ||
| } | ||
| repositories { | ||
| mavenCentral() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Add project specific ProGuard rules here. | ||
| # By default, the flags in this file are appended to flags specified | ||
| # in /Users/ellingtonkirby/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
| # 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 *; | ||
| #} | ||
|
|
||
| # Uncomment this to preserve the line number information for | ||
| # debugging stack traces. | ||
| #-keepattributes SourceFile,LineNumberTable | ||
|
|
||
| # If you keep the line number information, uncomment this to | ||
| # hide the original source file name. | ||
| #-renamesourcefileattribute SourceFile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="interactive.prolific.com.simcoe_mparticle" | ||
| > | ||
|
|
||
| <application> | ||
| <receiver | ||
| android:name="com.mparticle.ReferrerReceiver" | ||
| android:exported="true" | ||
| > | ||
| <intent-filter> | ||
| <action android:name="com.android.vending.INSTALL_REFERRER"/> | ||
| </intent-filter> | ||
| </receiver> | ||
| </application> | ||
| </manifest> |
61 changes: 61 additions & 0 deletions
61
simcoe-mparticle/src/main/java/com/prolificinteractive/mparticle/MPCommerceEventSimcoe.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package com.prolificinteractive.mparticle | ||
|
|
||
| import com.mparticle.commerce.CommerceEvent | ||
| import com.mparticle.commerce.Product | ||
| import com.prolificinteractive.simcoe.Properties | ||
|
|
||
|
|
||
| fun getCommerceEvent(action: String, products: Array<Product>, eventProperties: Properties?): CommerceEvent { | ||
| val product = products[0] | ||
| val productList: MutableList<Product> = products.copyOfRange(1, products.size).toMutableList() | ||
| val event = CommerceEvent.Builder(action, product) | ||
| event.products(productList) | ||
|
|
||
| val checkoutOptions = eventProperties?.get(MPCommerceEventKeys.CHECKOUT_OPTIONS.key).toString() | ||
| val checkoutStep = eventProperties?.get(MPCommerceEventKeys.CHECKOUT_STEP.key) as Int | ||
| val currency = eventProperties.get(MPCommerceEventKeys.CURRENCY.key).toString() | ||
| val nonInteractive = eventProperties.get(MPCommerceEventKeys.NON_INTERACTIVE.key) as Boolean | ||
| //TODO what to do with promotionContainer? | ||
| val productListName = eventProperties.get(MPCommerceEventKeys.PRODUCT_LIST_NAME.key).toString() | ||
| val productListSource = eventProperties.get(MPCommerceEventKeys.PRODUCT_LIST_SOURCE.key).toString() | ||
| val screenName = eventProperties.get(MPCommerceEventKeys.SCREEN_NAME.key).toString() | ||
| val transaction = getTransactionAttributes(eventProperties) | ||
|
|
||
| return event | ||
| .checkoutOptions(checkoutOptions) | ||
| .checkoutStep(checkoutStep) | ||
| .currency(currency) | ||
| .nonInteraction(nonInteractive) | ||
| .productListName(productListName) | ||
| .productListSource(productListSource) | ||
| .screen(screenName) | ||
| .transactionAttributes(transaction) | ||
| .build() | ||
| } | ||
|
|
||
| // | ||
| // MPCommerceEventKeys.swift | ||
| // Simcoe | ||
| // | ||
| /// The MPCommerceEvent keys available to use with eventProperties. | ||
| /// | ||
| /// - checkoutOptions: The checkout options. | ||
| /// - checkoutStep: The checkout step. | ||
| /// - currency: The currency. | ||
| /// - nonInteractive: The non interactive flag. | ||
| /// - promotionContainer: The promotion container. | ||
| /// - productListName: The product list name. | ||
| /// - productListSource: The product list source. | ||
| /// - screenName: The screen name. | ||
| /// - transactionAttributes: The transactions attributes. | ||
| enum class MPCommerceEventKeys(val key: String) { | ||
| CHECKOUT_OPTIONS("checkoutOptions"), | ||
| CHECKOUT_STEP("checkoutStep"), | ||
| CURRENCY("currency"), | ||
| NON_INTERACTIVE("nonInteractive"), | ||
| PROMOTION_CONTAINER("promotionContainer"), | ||
| PRODUCT_LIST_NAME("productListName"), | ||
| PRODUCT_LIST_SOURCE("productListSource"), | ||
| SCREEN_NAME("screenName"), | ||
| TRANSACTION_ATTRIBUTES("transactionAttributes"); | ||
| } |
64 changes: 64 additions & 0 deletions
64
simcoe-mparticle/src/main/java/com/prolificinteractive/mparticle/MPEventSimcoe.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.prolificinteractive.mparticle | ||
|
|
||
| import com.mparticle.MPEvent | ||
| import com.mparticle.MParticle | ||
| import com.mparticle.MParticle.EventType | ||
| import com.prolificinteractive.simcoe.Properties | ||
| import java.util.Date | ||
|
|
||
| fun eventData(type: MParticle.EventType, | ||
| name: String, | ||
| category: String? = null, | ||
| duration: Float? = null, | ||
| startTime: Date? = null, | ||
| endTime: Date? = null, | ||
| customFlags: Map<String, MutableList<String>>? = null, | ||
| info: Properties? = null): Properties { | ||
| var properties: Properties = mutableMapOf(MPEventKeys.EVENT_TYPE.key to type, MPEventKeys.NAME.key to name) | ||
|
|
||
| if (category != null) { | ||
| properties.plus(MPEventKeys.CATEGORY.key to category) | ||
| } | ||
|
|
||
| if (duration != null) { | ||
| properties.plus(MPEventKeys.DURATION.key to duration) | ||
| } | ||
|
|
||
| if (customFlags != null) { | ||
| properties.plus(MPEventKeys.CUSTOM_FLAGS.key to customFlags) | ||
| } | ||
|
|
||
| if (info != null) { | ||
| for ((key, value) in info) { | ||
| properties.plus(key to value) | ||
| } | ||
| } | ||
|
|
||
| return properties | ||
| } | ||
|
|
||
| @Suppress("UNCHECKED_CAST") | ||
| fun toEvent(data: Properties): MPEvent { | ||
| if (data[MPEventKeys.EVENT_TYPE.key] == null || data[MPEventKeys.NAME.key] == null) { | ||
| throw MPEventGenerationError("Failed to initialize the MPEvent. Check that you have a valid event name and type and try again. Names must not be an empty string.") | ||
| } | ||
| val eventType: MParticle.EventType = data[MPEventKeys.EVENT_TYPE.key] as EventType | ||
| val eventName: String = data[MPEventKeys.NAME.key] as String | ||
| var event: MPEvent = MPEvent.Builder(eventName, eventType) | ||
| .category(data[MPEventKeys.CATEGORY.key] as String) | ||
| .duration(data[MPEventKeys.DURATION.key] as Double) | ||
| .build() | ||
| event.customFlags.putAll(data[MPEventKeys.CUSTOM_FLAGS.key] as Map<String, MutableList<String>>) | ||
|
|
||
| return event | ||
| } | ||
|
|
||
| class MPEventGenerationError(message: String?) : RuntimeException(message) {} | ||
|
|
||
| enum class MPEventKeys(val key : String) { | ||
| EVENT_TYPE("SimcoeInternalMPEventType"), | ||
| CATEGORY("SimcoeInternalMPCategory"), | ||
| DURATION("SimcoeInternalMPDuration"), | ||
| NAME("SimcoeInternalName"), | ||
| CUSTOM_FLAGS("SimcoeInternalCustomFlags"); | ||
| } |
34 changes: 34 additions & 0 deletions
34
...particle/src/main/java/com/prolificinteractive/mparticle/MPTransactionAttributesSimcoe.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.prolificinteractive.mparticle | ||
|
|
||
| import com.mparticle.commerce.TransactionAttributes | ||
| import com.prolificinteractive.simcoe.Properties | ||
|
|
||
| fun getTransactionAttributes(properties: Properties?): TransactionAttributes { | ||
| val transaction = TransactionAttributes() | ||
| transaction.affiliation = properties?.get(MPTransactionAttributesKeys.AFFILIATION.key)?.toString() | ||
| transaction.couponCode = properties?.get(MPTransactionAttributesKeys.COUPON_CODE.key)?.toString() | ||
| transaction.revenue = properties?.get(MPTransactionAttributesKeys.REVENUE.key) as Double | ||
| transaction.shipping = properties?.get(MPTransactionAttributesKeys.SHIPPING.key) as Double | ||
| transaction.tax = properties?.get(MPTransactionAttributesKeys.TAX.key) as Double | ||
| transaction.id = properties?.get(MPTransactionAttributesKeys.TRANSACTION_ID.key)?.toString() | ||
|
|
||
| return transaction | ||
| } | ||
|
|
||
| /// The MPTransactionAttributes keys available. | ||
| /// | ||
| /// - affiliation: The affiliation. | ||
| /// - couponCode: The coupon code. | ||
| /// - revenue: The revenue amount. | ||
| /// - shipping: The shipping amount. | ||
| /// - tax: The tax amount. | ||
| /// - transactionId: The transaction Id. | ||
| enum class MPTransactionAttributesKeys(val key: String) { | ||
|
|
||
| AFFILIATION("affiliation"), | ||
| COUPON_CODE("couponCode"), | ||
| REVENUE("revenue"), | ||
| SHIPPING("shipping"), | ||
| TAX("tax"), | ||
| TRANSACTION_ID("transactionId"); | ||
| } |
47 changes: 47 additions & 0 deletions
47
simcoe-mparticle/src/main/java/com/prolificinteractive/mparticle/MpProduct.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package com.prolificinteractive.mparticle | ||
|
|
||
| import com.mparticle.commerce.Product | ||
| import com.prolificinteractive.simcoe.SimcoeProductConvertible | ||
|
|
||
|
|
||
| fun mpProduct(simcoeProductConvertible: SimcoeProductConvertible): Product { | ||
| val simcoeProduct = simcoeProductConvertible.toSimcoeProduct() | ||
| val product = Product. | ||
| Builder( | ||
| simcoeProduct.productName, | ||
| simcoeProduct.productId, | ||
| simcoeProduct.price ?: 0.toDouble() | ||
| ) | ||
| .quantity(simcoeProduct.quantity.toDouble()) | ||
|
|
||
|
|
||
| val properties = simcoeProduct.properties ?: return product.build() | ||
|
|
||
| product.brand(properties[MPProductKeys.BRAND.key] as? String ?: "") | ||
| product.category(properties[MPProductKeys.CATEGORY.key] as? String ?: "") | ||
| product.couponCode(properties[MPProductKeys.COUPON_CODE.key] as? String ?: "") | ||
| product.sku(properties[MPProductKeys.SKU.key] as? String ?: "") | ||
| product.position(properties[MPProductKeys.POSITION.key] as? Int ?: 0) | ||
|
|
||
| return product.build() | ||
| } | ||
|
|
||
|
|
||
| // | ||
| // Simcoe | ||
| // | ||
| /// The MPProduct keys available for use with additionalProperties. | ||
| /// | ||
| /// - brand: The product brand. | ||
| /// - category: A category to which the product belongs. | ||
| /// - couponCode: The coupon associated with the product. | ||
| /// - sku: The sku of the product. | ||
| /// - position: The position of the product on the screen or impression list. | ||
| /// - variant: The variant. | ||
| enum class MPProductKeys(val key: String) { | ||
| BRAND("brand"), | ||
| CATEGORY("category"), | ||
| COUPON_CODE("couponCode"), | ||
| SKU("sku"), | ||
| POSITION("position"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should probably update to beta now