Attribution
Orders placed through your Shop Mini will be automatically attributed to it. You can query attributions using the attributions
field in the Shop Minis Admin API, and your merchants can see stats in their Shop channel analytics dashboard. See below for how to attach custom attribution data to orders and how to attribute existing orders.
Attaching custom attribution data
You can attach custom attribution data to orders that originate within your Shop Mini when you use the
navigateToProduct
action or ProductLink
component:
await shopActions.navigateToProduct({
productId: product.id,
attribution: {
sourceName: 'foo',
sourceIdentifier: 'abc123',
},
})
<ProductLink
product={productFragment}
attribution={{ sourceName: 'foo', sourceIdentifier: 'abc123' }}
/>
Attribution currently only supports sourceName
and sourceIdentifier
fields. You can access this custom attribution data via the attributions
field in the Shop Minis Admin API, but it is not shared with merchants.
Attributing an existing order
If your Shop Mini allows users to add items to an existing order (e.g. a post-purchase upsell) you must manually trigger the attribution process using the createOrderAttribution
action:
await shopActions.createOrderAttribution({
orderId: 'gid://shopify/Order/123',
productVariantId: 'gid://shopify/ProductVariant/42',
})
You can optionally attach custom attribution data:
await shopActions.createOrderAttribution({
orderId: 'gid://shopify/Order/123',
productVariantId: 'gid://shopify/ProductVariant/42',
attribution: {
sourceName: 'foo',
sourceIdentifier: 'abc123',
},
})
You should do this before adding the line item to the order or presenting the payment screen to the user. The attribution will only activate once the payment is processed.
Querying attributed orders
You can query for attributed orders using the attributions
field in the Shop Minis Admin API. It accepts either an orderId
for fetching atttributions for a particular order,
or a shopDomain
for fetching all attributions for a particular shop.
- Attributions by order
- Attributions by shop
query($orderId: ID) {
attributions(orderId: $orderId) {
nodes {
lineItemId
orderId
shopDomain
fields {
key
value
}
}
}
}
query($shopDomain: String) {
attributions(shopDomain: $shopDomain) {
nodes {
lineItemId
orderId
shopDomain
fields {
key
value
}
}
}
}