searchspring / snap

Snap is Searchspring's latest front end integration SDK
https://searchspring.github.io/snap/
MIT License
8 stars 0 forks source link

Add `currency` context and `transactionTotal` #1064

Closed korgon closed 2 weeks ago

korgon commented 1 month ago

Since we cannot always normalize to a base price a currency context has been added for tracking different pricing.

For Snap tracking we will need to add a function for setCurrency({ code: 'USD' }) and also a way to provide that via context (similar to setShopper).

JSON Payload Examples:

Cart:

{
    "type": "cart",
    "category": "searchspring.shop.cart",
    "context": {
        "userId": "41f87850-65f5-4546-851c-f166109e57b9",
        "sessionId": "1c311c14-c33b-4222-952a-f17db729ea31",
        "shopperId": "{{$randomUserName}}",
        "website": {
            "trackingCode": "{{siteId}}"
        },
        "currency": {
            "code": "USD"
        }
    }
}

Transaction:

{
    "type": "transaction",
    "category": "searchspring.shop.transaction",
    "context": {
        "userId": "41f87850-65f5-4546-851c-f166109e57b9",
        "sessionId": "1c311c14-c33b-4222-952a-f17db729ea31",
        "shopperId": "{{$randomUserName}}",
        "website": {
            "trackingCode": "{{siteId}}"
        },
        "currency": {
            "code": "USD"
        }
    }
}

In addition, a new payload property transactionTotal should be able to be sent in the transaction (checkout) event payload. Currently the total sent in the payload typically represents the amount billed (taxes and all). The transactionTotal is essentially the total for the purchase minus the taxes and shipping. Documentation should be updated to reflect both of these changes.

For legacy tracking (is.gif) currencyCode and transactionTotal should be added as query parameters.