logPurchase static method

Future<void> logPurchase({
  1. String? affiliation,
  2. String? coupon,
  3. String? currency,
  4. List<String> items = const [],
  5. double? shipping,
  6. double? tax,
  7. String? transactionId,
  8. double? value,
})

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,
  });
}