Chord Commerce Event Tracking
Getting Started
Installing Chord Analytics
10 min
to install chord analytics on a shopify store, please start here using with shopify the @chordcommerce/analytics library provides simple methods for sending tracking events to chord from your website, with an optional debugging mode to validate event properties requirements the chord team will provide some of the configuration option values (see below) installation to install @chordcommerce/analytics , run the following command in your project directory npm install @chordcommerce/analytics\@v1 15 0 \# or yarn add @chordcommerce/analytics\@v1 15 0 usage initialize @chordcommerce/analytics as follows import { chordanalytics } from '@chordcommerce/analytics' const chord = new chordanalytics(options) // see below for configuration options chord trackcartviewed({ cart }) // sends a "cart viewed" event to the cdp once loaded, window\ chord will contain the chordanalytics instance in the browser using segment & chord cdp in parallel initialize both @chordcommerce/analytics and @segment/analytics next for testing purposes import { chordanalytics } from '@chordcommerce/analytics' import { analyticsbrowser } from '@segment/analytics next' // "cdp = window\ analytics" or "cdp = () => window\ analytics" const cdp = analyticsbrowser load({ writekey process env segment write key, }) const chord = new chordanalytics({ cdp, // optional remove to disable and only send to chordcdp cdpdomain process env chord cdp domain, cdpwritekey process env chord cdp write key, formatters { }, metadata { }, }) chord page() chord trackproductadded({ }) configuration @chordcommerce/analytics can be initialized with the following options property required description cdp false required when using a cdp other than chord a reference to the cdp library, or a function that returns a reference to the cdp library for example, if using segment's analytics js library, this could be window\ analytics or () => window\ analytics cdpdomain true the chord cdp domain to be provided by the chord team cdpwritekey true the chord cdp write key to be provided by the chord team awaitconsent false if true, the client will not load load p js until consent is given for up to 1 minute after 1 minute, p js will load if consent is not given, events will not be forwarded to the cdp if false, the analytics client will load p js immediately consent false defines which consent adapter the client should use providers currently supported are "ketch", "shopify", "onetrust", and "segment" debug false defaults to false when set to true , events are validated against chord's tracking plan and errors are logged we recommend enabling this for development and disabling for production enablelogging false defaults to true when set to true , errors are logged using console log formatters true functions that are used to construct tracking events there are two types of formatters, objects and events formatters objects is required see formatters docid\ qqjjglkiarnul56wnjzof for more details metadata true event metadata see below for details namespace false defaults to chord changes where chord is globally available (e g window\ chord ) only applicable when using chord cdp stripnull false defaults to true when set to true , event properties with a null value are removed cdps typically treat null and undefined as separate values, so be sure you intend to send null values before setting to false if cdp , cdpdomain and cdpwritekey are all omitted, no tracking events are sent metadata property required description metadata i18n currency true the order currency in iso 4217 currency code, uppercase for example, usd metadata i18n locale true the order locale for example, en us metadata ownership omsid true a uuid assigned by chord this identifier is unique to the store, and will be the same across every environment and cdp source for a given store metadata ownership storeid true a uuid assigned by chord this identifier is unique to the store, and will be the same across every environment and cdp source for a given store metadata ownership tenantid true a uuid assigned by chord this identifier is unique to the store, and will be the same across every environment and cdp source for a given store metadata platform name true the name of the e commerce platform used for example, shopify metadata platform type true the type of platform where the event originated either web or pos metadata store domain true the domain of the site where the event originated for shopify, this should be the store slug that comes before myshopify com formatters formatters are javascript functions that are used to construct tracking event properties there are two types of formatters, objects and events you must define object formatters event formatters are optional see chordβs documentation https //docs chord co/analytics getting started#fgwx7 for more details and example formatters object formatters a formatter must be provided for each of the four core data types that are used in chord events this formatter function transforms input data into the type chord expects see formatters docid\ qqjjglkiarnul56wnjzof for more details on object formatters property required description formatters objects cart true a function that creates a cart object formatters objects checkout true a function that creates a checkout object formatters objects lineitem true a function that creates a line item object formatters objects product true a function that creates a product object event formatters a formatter can be provided for each event this formatter is used to transform the event properties of a specific event after chord constructs the event, just before it's sent to the cdp see formatters docid\ qqjjglkiarnul56wnjzof for more details on event formatters using with typescript optionally, you can instantiate chordanalytics with a custom type argument describing your data to improve type safety for formatters and sdk functions for instance, if you're working with objects like cart , product , etc , from a shopify storefront api query, you might already have types like storefrontcart defined for the response instantiate chordanalytics with a type argument interface objecttypes { cart storefrontcart checkout storefrontcart lineitem storefrontlineitem product storefrontproduct } const chord = new chordanalytics\<objecttypes>({ options }) now, when you use an sdk method like chord trackcartviewed({ cart }) , cart has the storefrontcart type formatter types also support an optional generic type parameter for the function argument import type { cartformatter } from '@chordcommerce/analytics' export const cartformatter cartformatter\<storefrontcart> = (props) => { const { cart } = props // `cart` has type `storefrontcart` return { } } api reference see chordβs documentation for a full api reference support for support with setup and configuration, please contact chord directly at help\@chord co