logPurchase static method
E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user.
{@template SupabaseAnalyticsAddons.logPurchase}
affiliation
: A product affiliation to designate a supplying
company or brick and mortar store location
coupon
: Coupon code used for a purchase
currency
: Currency of the purchase or items associated with the
event, in 3-letter ISO_4217
format. If not provided, the currency is fetched from the device
items
: The list of items involved in the transaction
shipping
: Shipping cost associated with a transaction
tax
: Tax cost associated with a transaction
transactionId
: The unique identifier of a transaction
An AssertionError is thrown if the currency couldn't be fetched {@endTemplate}
Implementation
static Future<void> logPurchase({
String? affiliation,
String? coupon,
String? currency,
List<String> items = const [],
double? shipping,
double? tax,
String? transactionId,
double? value,
}) {
currency ??= NumberFormat.simpleCurrency(
locale: SupabaseAddons.systemLocale,
).currencyName;
if (value != null || tax != null || shipping != null) {
assert(
currency != null,
'If you supply the value parameter, you must also supply parameter so that revenue metrics can be computed accurately',
);
}
return logEvent(name: 'purchase', params: {
'affiliation': affiliation,
'coupon': coupon,
'currency': currency,
'items': items,
'shipping': shipping,
'tax': tax,
'transactionId': transactionId,
'value': value,
});
}