Skip to content

Commit

Permalink
feat: add in readme changes (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchuangatmp authored Mar 17, 2022
1 parent 6d9309f commit 70be06d
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 7 deletions.
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# mparticle-android-sample-app-internal
This repo contains a Kotlin Android Application that implements and demonstrates the functionality of the mParticle Android SDK.
<img src="https://static.mparticle.com/sdk/mp_logo_black.svg" width="280"><br>

# mParticle Android Sample Apps

[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

Hello! This is the mParticle Android Sample Apps Repository. We've built a collection of fully functional sample apps that provide a best practice approach to integrate with our [mParticle Android SDK](https://github.com/mparticle/mparticle-android-sdk) and other services we provide.

## Getting Started

This repository serves as directory of individual, self-contained, Sample Apps. Each application is a full project with working code, detailed implementation documentation and an integrated CI/CD pipeline via Github Actions.

Our recommenation is to fork or download the entire repository and open a specific project in Android Studio or editor of choice. This will provide full project settings, including linting.

**NOTE** These Sample Apps require a mParticle account with an API key.

While the code might run and build without mParticle credentials, the SDKs will not upload events to our servers and will generate errors.

Please visit [our docs](https://docs.mparticle.com/guides/getting-started/create-an-input) for more details on setting up an API Key.

### Sample Apps Directory

Below is a list of sample apps, with a brief description of their intended use case. Please navigate to an individual Sample App's README.md file for specific use cases and implementation details.

| App Name | Path | Description |
| ---------- | -------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| Higgs Shop | [core-sdk-samples/higgs-shop-sample-app](core-sdk-samples/higgs-shop-sample-app) | An example of an e-commerce application |

## Contributing

Thank you for thinking about contributing to the mParticle Sample Apps Project.

Please review the [CONTRIBUTING.md](CONTRIBUTING.md) file for details.

## Support

<[email protected]>

## License

The mParticle Android SDK is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). See the LICENSE file for more info.

THE MPARTICLE SAMPLE APPS, INCLUDING ANY ASSOCIATED MPARTICLE APIs AND MPARTICLE SDKs, ARE PROVIDED ON AN “AS-IS” BASIS, AND MPARTICLE HEREBY DISCLAIMS ANY AND ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS, IMPLIED (EITHER IN FACT OR BY OPERATION OF LAW), OR STATUTORY, AS TO ANY MATTER WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUALITY, ACCURACY, TITLE, AND NON-INFRINGEMENT. MPARTICLE DOES NOT WARRANT THAT THE MPARTICLE SAMPLE APP, INCLUDING ANY ASSOCIATED, MPARTICLE SDKs OR MPARTICLE APIs, ARE ERROR-FREE OR THAT OPERATION THEREOF WILL BE SECURE OR UNINTERRUPTED.
79 changes: 78 additions & 1 deletion core-sdk-samples/higgs-shop-sample-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,87 @@ While the code might run and build without mParticle credentials, the SDKs will

Please visit https://docs.mparticle.com/ for more details on setting up an API Key.

## Events used in this app

To make things simple yet declarative, this application has been built in such a way to keep event tracking close to the components that might logically trigger them rather than a fully DRY implementation. We've opted to be more repetitive so examples are consise and documented as necessary.

Please feel free to also visit our [Doc Site](https://docs.mparticle.com/) to gain more familiarity with some of the more advanced features of mParticle.

### Screen Views

In cases where it is necessary to track visitors as they navigate your Android Application, mParticle offers [Screen View Tracking](https://docs.mparticle.com/developers/sdk/android/screen-tracking/).

For example

```kotlin
val screenInfo = HashMap<String, String>()
screenInfo["rating"] = "5"
screenInfo["property_type"] = "hotel"

MParticle.getInstance().logScreen("Destination Details", screenInfo)
```

In some cases, we fire a _Commerce Event_ instead of a _Page View_ to track more e-Commerce related attributes.

### Custom Events

Most often, you will need to use [Custom Events](https://docs.mparticle.com/developers/sdk/android/event-tracking/#custom-events) to track events in a way that is unique to your use case. mParticle provides types of _Custom Events_ ranging from Navigation Events to Social Media Engagement and are mostly used to organize your data in a way that makes sense to you.

Many of our components in `/src/components` make use of these events, particularly the `NavigationMenuItem` Component.

### Commerce Events

This Sample App emulates a simple e-Commerce application and makes heavy use of mParticle's [Commerce Events](https://docs.mparticle.com/developers/sdk/android/commerce-tracking/).

Some events used in this application:

- Add To Cart
- Remove From Cart
- Product Detail
- Product Impression
- Checkout
- Purchase

Most _Commerce Events_ follow a similar pattern, requiring that you first generate an **mParticle Product** Object, which then gets passed into the `logEvent` method.

You should map your own product attributes to be consistent with your [Data Plan](https://docs.mparticle.com/guides/data-master/introduction/) if you are leveraging that feature. Using Data Plans ensures data consistency within an app and across devices.

```kotlin
// 1. Create the products
val product = Product.Builder("Double Room - Econ Rate", "econ-1", 100.00)
.quantity(4.0)
.build()

// 2. Summarize the transaction
val attributes = TransactionAttributes("foo-transaction-id")
.setRevenue(430.00)
.setTax(30.00)

// 3. Log the purchase event
val event = CommerceEvent.Builder(Product.PURCHASE, product)
.transactionAttributes(attributes)
.build()
MParticle.getInstance().logEvent(event)
```

## Discovering Events

As a developer, sometimes the best way to learn is to just dig into the code or your debugging tools. To that end, this sample app ships with a verbose logger that you can view details of what our SDK is doing within Android Studio's logcat.

### Live Stream

To verify that your events have arrived at mParticle's servers, or to compare your Android Events from that of our other SDKs, you can also visit our [Live Stream](https://docs.mparticle.com/guides/platform-guide/live-stream/).

This will not only show your data as it enters mParticle, but also as your data is forwarded to our various partner services and integrations (if enabled).

## Development Notes

This project is built in Kotlin and follows MVVM design patterns and uses Retrofit (networking), Room (ORM/database), and Glide (image loading)

## Support

<[email protected]>

## License

The mParticle Web SDK is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). See the LICENSE file for more info.
The mParticle Android SDK is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). See the LICENSE file for more info.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ class LandingActivity : AppCompatActivity() {
setContentView(R.layout.activity_landing)
MParticle.getInstance()?.logScreen("Landing")

val btnCTA = findViewById(R.id.landing_cta) as Button
if(hasApiKey()) {
val btnCTA = findViewById(R.id.landing_cta) as Button
btnCTA.isClickable = true
btnCTA.alpha = 1.0F
btnCTA.setOnClickListener {
val event = MPEvent.Builder("Landing Button Click", MParticle.EventType.Other)
.build()
Expand All @@ -33,6 +35,8 @@ class LandingActivity : AppCompatActivity() {
startActivity(intent)
}
} else {
btnCTA.isClickable = false
btnCTA.alpha = 0.3F
showBlankAPIKeyAlert()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class AccountFragment : Fragment() {
false -> {
//no user so login
val identityRequest = IdentityApiRequest.withEmptyUser()
.email("higgs@example.com")
.customerId("123456")
.email("higgs@mparticle.com")
.customerId("higgs123456")
.build()
MParticle.getInstance()?.Identity()?.login(identityRequest)?.addSuccessListener {
accountViewModel.login()
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
android:text="@string/account_title"
android:textColor="@color/white"
android:textStyle="bold"
android:fontFamily="@font/lato_regular"
android:textSize="24sp"
/>
<com.google.android.material.textfield.TextInputLayout
Expand Down Expand Up @@ -54,7 +55,7 @@
android:layout_height="wrap_content"
android:text="@string/account_disclaimer"
android:textColor="@color/white"
app:fontFamily="sans-serif"
app:fontFamily="@font/lato_regular"
android:alpha=".6"
android:gravity="center"
android:layout_marginBottom="100dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@
<item name="colorSecondaryVariant">@color/gray_999999</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:fontFamily">@font/lato_regular</item>
</style>

<!-- Splash/Landing theme -->
<style name="Theme.mParticle.SampleApp.Splash" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_gradient</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:fontFamily">@font/lato_regular</item>
</style>

<!-- Button theme -->
<style name="Theme.mParticle.SampleApp.Button">
<item name="colorPrimary">@color/blue_4079FE</item>
<item name="colorOnPrimary">@color/white</item>
<item name="android:textColor">@color/white</item>
<item name="android:fontFamily">@font/lato_regular</item>
</style>

<!-- TextInputLayout theme -->
<style name="Theme.mParticle.SampleApp.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="android:fontFamily">@font/lato_regular</item>
<item name="android:textColorHint">@color/white</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">16sp</item>
Expand All @@ -48,6 +52,7 @@

<style name="TextAppearance.AppTheme.TextInputLayout.HintTextAlt" parent="TextAppearance.MaterialComponents.Subtitle2">
<item name="android:textColor">@color/white</item>
<item name="android:fontFamily">@font/lato_regular</item>
</style>

<!-- TextInputEditText theme -->
Expand Down Expand Up @@ -81,6 +86,7 @@
<item name="android:paddingEnd">15dp</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">16sp</item>
<item name="android:fontFamily">@font/lato_regular</item>
</style>


Expand Down

0 comments on commit 70be06d

Please sign in to comment.