Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.1.2-2'
ext.kotlin_version = '1.1.4-3'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.4.0-alpha7'
classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
Copy link
Member

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

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
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
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include ':simcoe'
include ':simcoe', ':simcoe-mparticle'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the line

include ':simcoe-mixpanel'
include ':sample'
1 change: 1 addition & 0 deletions simcoe-mparticle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
34 changes: 34 additions & 0 deletions simcoe-mparticle/build.gradle
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()
}
25 changes: 25 additions & 0 deletions simcoe-mparticle/proguard-rules.pro
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
15 changes: 15 additions & 0 deletions simcoe-mparticle/src/main/AndroidManifest.xml
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>
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");
}
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");
}
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");
}
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");
}
Loading