segment-integrations / analytics-ios-integration-adobe-analytics

Segment's Adobe Analytics Integration for Analytics-iOS
MIT License
1 stars 2 forks source link

Implements ECommerce #9

Closed ladanazita closed 6 years ago

ladanazita commented 6 years ago
Adobe has a few reserved ecommerce events which Segment maps to.
Specifically `scAdd` for `Product Added`, `scRemove` for `Product Removed`
`scView` for `Cart Viewed`, `scCheckout` for `Checkout Started`, and
`purchase` for `Order Completed`.

Segment does not have a spec'd event for Adobe's `scOpen` event,
which has been described in Adobe as a "Carts" event. Segment
will not support sending this.

Adobe also expects products to be passed in with the key `&&products` and
as a String formatted like so:
`"Category;Product;Quantity;Price;eventN=X[|eventN2=X2];eVarN=merch_category[|eVarN2=merch_category2]"`

Product is a required argument, so if this is not present, Segment does not create the
`&&products` String. This value can be the product name, sku, or productId,
which is configured via the Segment setting `productIdentifier`.

If the other values in the String are missing, Segment
will leave the space empty but keep the `;` delimiter to preserve the order
of the product properties.

Segment does not strip all commas and semicolons from product and
category names, which aligns with the behavior of the analytics.js
Adobe-Analytics component. Segment documents that users should not
pass these characters in.

If `&&products` contains multiple products, the end of a product will
be delimited by a `,`.

Segment will also send in any additional `contextDataVariables` configured
in Segment settings.

Adobe allows you to send `&&products` via a `trackAction` or `trackState` call.
Since Segment does not spec sending ecommerce data on `screen`, Segment
will only support sending `&&products` on `track` as a `trackAction` call.

If a product-specific event is triggered, it must also be sent with the
`&&events` variable. Segment will send in the Segment spec'd Ecommerce
event as the `&&events` variable.

This initial implementation does not support merchandising categories,
product-specific currency events, and order-wide currency events. This
will only support non-purchase and purchase events, while the additional
functionality will come in individual branches if we choose to support
them.
ladanazita commented 6 years ago

@f2prateek and @brennan implemented requested changes.

For Brennan's comment, as discussed I decided not to consider other potential ecommerce events mapped in eventsV2. We can revisit this later when we scope out order wide currency events.

Note that if an ecommerce event is triggered that is not one of the reserved ecommerce events in Adobe, the logic will never send &&products since we are only continuing into the mapProducts logic if event.name == Product Added, Product Removed, Cart Viewed, Checkout Started or Order Completed.

If the event name does match up, we will send over the Adobe event name as both the event name argument through trackAction and as the value for &&events.

ladanazita commented 6 years ago

ping @f2prateek @brennan

ladanazita commented 6 years ago

@f2prateek As requested, I moved the logic which built the products String outside of formatProducts. formatProducts no longer takes in the product string.

Also added a giant comment showing the expected input of formatProduct and output.