mParticle Integration Guide - Web

mParticle users can integrate Button using our mParticle ButtonKit. Once completed, you will be enabled to receive users from the Button Marketplace. In this guide, we will:

  1. Add the Mobile Web SDK
  2. Hook Up mParticle
  3. Report Orders to Button via mParticle
  4. Report Adjustments and Cancellations to Button
  5. Test Your Integration

What is a Button integration via mParticle?

For Brands that already work with mParticle, the mParticle SDK provides an option to send orders to Button through your existing partnership with minimal integration work.

If you're unsure if this is the correct integration path for your company, please talk to your Button Partner Success Manager.

The ButtonKit

The ButtonKit provides features on top of the standard mParticle SDK. These features are required to enable Button's linking and affiliation products. They are

  • Post-install deeplinking
  • Automatic user attribution collection

Including the ButtonKit will also include the base mParticle SDK.

Requirements

Before we begin, you should have the following:

Add the Mobile Web SDK

Follow the steps in the mParticle documentation to add the Mobile Web SDK to your application.

❗️

Note

The Mobile Web SDK requires one extra step to explicitly set the integration attribute necessary for our integration. Please note the snippet here.

Hook Up mParticle

Connect your mWeb workspace to Button.
You will need to input your Button Application ID, which you can access from your organization’s Button dashboard.
For more information on setting up a new mParticle connection, see the Platform Guide.

Reporting Orders

To report orders with a mParticle integration, you must use the mParticle SDK to report eCommerce Events.

mParticle provides thorough documentation of these methods in their SDK documentation.
A Brand can construct MPCommerceEvents in the mParticle SDK via the checkout API or manually.
Which method a Brand chooses is not relevant to Button as long as the required fields are included.

Button requires the reporting of a subset of the eCommerce event fields. The taxonomy of fields Button expects is as follows.

A Brand must use the eCommerce class. Set the ISO 4217 currency code for the eCommerce object using setCurrencyCode.

Using that object, create products using createProduct. Each product must include:

  • sku
  • quantity
  • price
  • name

Create a TransactionAttributes object using createTransactionAttributes. It must include:

  • id
  • revenue

For each product, log the purchase using the same transationAttributes.

You may also use the Cart API. Using the cart API requires the same fields but may fit better into your existing integration.


Report Adjustments and Cancellations to Button

Button requires all mParticle integrated Brands to report returns, adjustments, and cancellations via a batch file upload.
This section details the process to deliver and format this file correctly.

The enclosed CSV snippets refer to the following sample order data:

Sample Order Data

This is an example mParticle payload that would be received by Button. We'll be referencing and adjusting this order in the following sections.

[
   {
      "currencycode":"USD",
      "type":"PRODUCT_ACTION",
      "transactionid":"1112224788",
      "products":[
         {
            "quantity":"1.0",
            "totalamount":"10.99",
            "price":"10.99",
            "name":"Colombian Supremo Coffee, Single-Serve Cups (100 ct.)",
            "attributes":{
            },
            "id":"202091",
            "position":"0",
            "category":"ci16953338243"
         },
         {
            "quantity":"3.0",
            "totalamount":"60.45",
            "price":"20.15",
            "name":"Comfort Care Baby Diapers, Size 4, 22 - 37 lbs. (210 ct.)",
            "attributes":{
            },
            "id":"894036055",
            "position":"0",
            "category":"ci16953331111"
         }
      ],
      "shippingamount":"0.0",
      "totalamount":"73.65",
      "action":"PURCHASE",
      "taxamount":"2.21",
      "attributes":{
         "fulfillment":"delivery"
      },
   }
]

This will create a Button transaction that you can query which looks as such (this only includes relevant fields for brevity):

{
   "order_total":6982,
   "order_line_items":[
      {
         "quantity":1,
         "total":1099,
         "sku":"202091",
         "description":"Member's Mark Colombian Supremo Coffee, Single-Serve Cups (100 ct.)"
      },
      {
         "quantity":3,
         "total":6045,
         "sku":"894036055",
         "description":"Member's Mark Comfort Care Baby Diapers, Size 4, 22 - 37 lbs. (210 ct.)"
      }
   ]
}

General Guidelines

  • Button will provide you with a dedicated SFTP directory for uploading your batch files
  • The batch file name should include the upload date in its file name
  • Batch files should be delivered in a comma-separated value (CSV) format, dropped to the SFTP site on a recurring basis at a mutually agreed upon interval (e.g. daily)
  • The file should contain all adjusted and cancelled orders that occurred since the previous upload (e.g. the previous day from 00:00:00 UTC to 23:59:59 UTC)
    • For the first upload, the file should contain records from the previous interval (e.g. yesterday, last week)
  • Each [Order ID/Line Item] combination should have its own row entry (i.e. if there are 3 items in the order, there should be 3 rows: 1 for each line item)
  • All values are on a line item (product in mParticle) basis except for Order ID

All of these scenarios must be accounted for:

  • Line Item quantity decrease
  • Line Item cancellation (removal)
  • Full order cancellations
  • Removing fraudulent orders (i.e. orders Button has that do not exist in your OMS)

Notes on Syntax

The shorthand products[].X is used to indicate that field X is present on each item in the products array reported to mParticle. For example, products[].id represents the ID field on an item in the product array.

CSV Headers and Definitions

  • DATE_UPDATED: date & time the order was adjusted (RFC3339 format in UTC time)
  • ORDER_ID: Your Brand order ID. This value must be unique within your organization (if it is not, please notify your Button contact). Must be the same value as the transactionid field reported to mParticle in the original commerce event.
  • PRODUCT_REVENUE (integer): total revenue for the line item (xx.xx). This will replace the products[].totalamount field reported to mParticle in the original order.
  • CURRENCY (string): currency used for the purchase (String in ISO ALPHA-3 format)
  • PRODUCT_SKU (string): The SKU for the product item sold. Must be the same value as the products[].id field reported to mParticle in the original order.
  • PRODUCT_DESCRIPTION (string): description of the line-item, e.g. “large t-shirt”. This will replace the products[].name field reported to mParticle in the original order.
  • PRODUCT_QTY (integer): number of line item units purchased. This will replace the products[].quantity field reported to mParticle in the original order.
  • ACTION (string): The action to apply to the order or line item, as relevant. The possible values are as follows:
    • invalidate: This tells Button to delete an unverified order
    • cancel: This tells Button to remove a fully returned/cancelled order. Note: Only use this action when you intend to cancel an entire order. Partial returns are considered order adjustments and should follow that format.
    • adjust: This tells Button to replace the current state of the line item with what’s in the CSV file
    • <empty>: Leaving this column empty tells Button the listed line item was not adjusted and is still valid for an otherwise-adjusted order. Note: this case only occurs for orders that have other line items with adjust action(s)

Reporting Adjustments

  1. Extract Orders Adjusted From OMS Since Last Batch File Upload - Extract details for all orders were adjusted since the last Batch File Upload (e.g. from 00:00:00-23:59:59 UTC yesterday)
  2. Write Adjustments to New Batch File - Following the conventions outlined above, write all order adjustments to the new batch file. Refer to the below example.

An order is considered an "Adjusted Order" when at least one line item in the order has changed, but the entire order has not been cancelled. We expect Adjusted orders to be reported in their current state (not the delta). Per the below examples, the following scenarios must be accounted for:

  • Line items where quantity changes. Report the new quantity with an adjust action.
  • Line items that are fully returned/cancelled. Omit these items from the CSV. Do not use a cancel action.
  • Remaining, unadjusted line items. Include these line items in their current state, with no action specified.

Sample Adjustment Row

If the purchasing user returns the coffee, we would expect the coffee be omitted in the CSV. Note that that the diapers are still present since they did not change. The example row is as follows:

DATE_UPDATED,ORDER_ID,PRODUCT_REVENUE,CURRENCY,PRODUCT_SKU,PRODUCT_DESCRIPTION,PRODUCT_QTY,ACTION
2018-09-01T00:00:00Z,1112224788,60.45,USD,894036055,"Member's Mark Comfort Care Baby Diapers, Size 4, 22 - 37 lbs. (210 ct.)",3,

If the purchasing user returned the coffee and two of the diapers (they bought 3) we would expect the coffee line item to be omitted, and the new state of the diaper item (not the delta) to show up with an adjust action. The resulting single example row is as follows:

DATE_UPDATED,ORDER_ID,PRODUCT_REVENUE,CURRENCY,PRODUCT_SKU,PRODUCT_DESCRIPTION,PRODUCT_QTY,ACTION
2018-09-01T00:00:00Z,1112224788,20.15,USD,894036055,"Member's Mark Comfort Care Baby Diapers, Size 4, 22 - 37 lbs. (210 ct.)",1,adjust

If the user only returned two of the diapers (they bought 3) we would expect the coffee line item to be included with no changes, and the new state of the diaper item (not the delta) to show up with an adjust action. The example rows are as follows:

DATE_UPDATED,ORDER_ID,PRODUCT_REVENUE,CURRENCY,PRODUCT_SKU,PRODUCT_DESCRIPTION,PRODUCT_QTY,ACTION
2018-09-01T00:00:00Z,1112224788,10.99,USD,202091,"Member's Mark Colombian Supremo Coffee, Single-Serve Cups (100 ct.)",1,
2018-09-01T00:00:00Z,1112224788,20.15,USD,894036055,"Member's Mark Comfort Care Baby Diapers, Size 4, 22 - 37 lbs. (210 ct.)",1,adjust

Reporting Cancellations

  1. Extract Orders Cancelled From OMS Since Last Batch File Upload - Extract details for all orders that were cancelled since the last Batch File Upload (e.g. from 00:00:00-23:59:59 UTC yesterday)
  2. Write Cancellations to New Batch File - Following the conventions outlined above, write all order cancellations to the new batch file. Refer to the below example.

Sample Cancellation Row

If the purchasing user returned the whole order, we would expect the order to show up in the file with a cancel action. The example row is as follows.

DATE_UPDATED,ORDER_ID,PRODUCT_REVENUE,CURRENCY,PRODUCT_SKU,PRODUCT_DESCRIPTION,PRODUCT_QTY,ACTION
2018-09-01T00:00:00Z,1112224788,,,,,,cancel

Reporting Invalidations

Reporting invalidations is only a requirement for partners who report orders client side. Those who report server side are exempt from this fraud-prevention measure.
  1. Extract All Orders From OMS Since Last Batch File Upload - Extract details for all orders that were placed or modified since the last Batch File Upload (e.g. from 00:00:00-23:59:59 UTC yesterday). Orders can be retrieved through the Export Tool in your dashboard, or they can be retrieved from our Transactions API.
  2. Cross Reference Button Orders with OMS Orders - Compare orders in the Button extract with orders in your OMS. Orders present in Button but missing from your OMS should be invalidated.
  3. Write Invalidations to New Batch File - Following the conventions outlined here in the resources, write all order invalidations to the new batch file. Refer to the below example.

Sample Invalidation Row

If the order was fraudulent, we would expect the order to show up with an invalidate action. The example rows are as follows.

DATE_UPDATED,ORDER_ID,PRODUCT_REVENUE,CURRENCY,PRODUCT_SKU,PRODUCT_DESCRIPTION,PRODUCT_QTY,ACTION
2018-09-01T00:00:00Z,1112224788,,,,,,invalidate

Upload New Batch File to SFTP Site

  1. Upload New Batch File to the SFTP Site - Your Partner Support Manager will share your password with you. Place the newly-generated CSV batch file in the /uploads directory on uploads.usebutton.com.

Test your Integration

You can test the mParticle side of the integration by performing the following actions in development mode, and following along in the mParticle live stream. You should see the following as both inbound and outbound data to Button, for each mParticle workspace connection:

  • Application Install
  • Application open from deep link. You can verify that the mParticle SDK automatically collects the btn_ref within each Application State Transition message, specifically within the “launch referrer” property.
  • eCommerce Purchases

To test the full Button integration, please contact your Button representative.