Braze JavaScript SDK
    Preparing search index...

    Function logPurchase

    • Reports that the current user made an in-app purchase. Useful for tracking and segmenting users.

      Parameters

      • productId: string

        A string identifier for the product purchased, e.g. an SKU. Value is limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation.

      • price: number

        The price paid. Base units depend on the currency. As an example, USD should be reported as Dollars.Cents, whereas JPY should be reported as a whole number of Yen. All provided values will be rounded to two digits with toFixed(2)

      • currencyCode:
            | "AED"
            | "AFN"
            | "ALL"
            | "AMD"
            | "ANG"
            | "AOA"
            | "ARS"
            | "AUD"
            | "AWG"
            | "AZN"
            | "BAM"
            | "BBD"
            | "BDT"
            | "BGN"
            | "BHD"
            | "BIF"
            | "BMD"
            | "BND"
            | "BOB"
            | "BRL"
            | "BSD"
            | "BTC"
            | "BTN"
            | "BWP"
            | "BYR"
            | "BZD"
            | "CAD"
            | "CDF"
            | "CHF"
            | "CLF"
            | "CLP"
            | "CNY"
            | "COP"
            | "CRC"
            | "CUC"
            | "CUP"
            | "CVE"
            | "CZK"
            | "DJF"
            | "DKK"
            | "DOP"
            | "DZD"
            | "EEK"
            | "EGP"
            | "ERN"
            | "ETB"
            | "EUR"
            | "FJD"
            | "FKP"
            | "GBP"
            | "GEL"
            | "GGP"
            | "GHS"
            | "GIP"
            | "GMD"
            | "GNF"
            | "GTQ"
            | "GYD"
            | "HKD"
            | "HNL"
            | "HRK"
            | "HTG"
            | "HUF"
            | "IDR"
            | "ILS"
            | "IMP"
            | "INR"
            | "IQD"
            | "IRR"
            | "ISK"
            | "JEP"
            | "JMD"
            | "JOD"
            | "JPY"
            | "KES"
            | "KGS"
            | "KHR"
            | "KMF"
            | "KPW"
            | "KRW"
            | "KWD"
            | "KYD"
            | "KZT"
            | "LAK"
            | "LBP"
            | "LKR"
            | "LRD"
            | "LSL"
            | "LTL"
            | "LVL"
            | "LYD"
            | "MAD"
            | "MDL"
            | "MGA"
            | "MKD"
            | "MMK"
            | "MNT"
            | "MOP"
            | "MRO"
            | "MTL"
            | "MUR"
            | "MVR"
            | "MWK"
            | "MXN"
            | "MYR"
            | "MZN"
            | "NAD"
            | "NGN"
            | "NIO"
            | "NOK"
            | "NPR"
            | "NZD"
            | "OMR"
            | "PAB"
            | "PEN"
            | "PGK"
            | "PHP"
            | "PKR"
            | "PLN"
            | "PYG"
            | "QAR"
            | "RON"
            | "RSD"
            | "RUB"
            | "RWF"
            | "SAR"
            | "SBD"
            | "SCR"
            | "SDG"
            | "SEK"
            | "SGD"
            | "SHP"
            | "SLL"
            | "SOS"
            | "SRD"
            | "STD"
            | "SVC"
            | "SYP"
            | "SZL"
            | "THB"
            | "TJS"
            | "TMT"
            | "TND"
            | "TOP"
            | "TRY"
            | "TTD"
            | "TWD"
            | "TZS"
            | "UAH"
            | "UGX"
            | "USD"
            | "UYU"
            | "UZS"
            | "VEF"
            | "VND"
            | "VUV"
            | "WST"
            | "XAF"
            | "XAG"
            | "XAU"
            | "XCD"
            | "XDR"
            | "XOF"
            | "XPD"
            | "XPF"
            | "XPT"
            | "YER"
            | "ZAR"
            | "ZMK"
            | "ZMW"
            | "ZWL" = "USD"

        Default USD. Currencies should be represented as an ISO 4217 currency code. Supported currency symbols include: AED, AFN, ALL, AMD, ANG, AOA, ARS, AUD, AWG, AZN, BAM, BBD, BDT, BGN, BHD, BIF, BMD, BND, BOB, BRL, BSD, BTC, BTN, BWP, BYR, BZD, CAD, CDF, CHF, CLF, CLP, CNY, COP, CRC, CUC, CUP, CVE, CZK, DJF, DKK, DOP, DZD, EEK, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GGP, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, IMP, INR, IQD, IRR, ISK, JEP, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW, KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LTL, LVL, LYD, MAD, MDL, MGA, MKD, MMK, MNT, MOP, MRO, MTL, MUR, MVR, MWK, MXN, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN, PGK, PHP, PKR, PLN, PYG, QAR, RON, RSD, RUB, RWF, SAR, SBD, SCR, SDG, SEK, SGD, SHP, SLL, SOS, SRD, STD, SVC, SYP, SZL, THB, TJS, TMT, TND, TOP, TRY, TTD, TWD, TZS, UAH, UGX, USD, UYU, UZS, VEF, VND, VUV, WST, XAF, XAG, XAU, XCD, XDR, XOF, XPD, XPF, XPT, YER, ZAR, ZMK, ZMW, and ZWL. Any other provided currency symbol will result in a logged warning and no other action taken by the SDK.

      • quantity: number = 1

        Default 1. The quantity of items purchased expressed as a whole number. Must be at least 1 and at most 100.

      • OptionalpurchaseProperties: GenericObject

        Hash of properties for this purchase. Keys are limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation. Values can be numeric, boolean, Date objects, strings 255 characters or shorter, or nested objects whose values can be numeric, boolean, Date objects, arrays, strings, or null. Total size of purchase properties cannot exceed 50KB.

      Returns Promise<boolean | undefined>

      Resolves to a boolean that indicates whether the event was successfully enqueued. Resolves to undefined if the SDK is not initialized.