Skip to main content

Quick Start

👋 Hi there. Here’s a quick instruction on how to install Logger and track events on your website:

Add script tag into the page

To start logging you’ll need to insert scripts on the page:

index.html - Remote files importing
<body>
...
<!--
Import JavaScript file.
Prefered location is in the bottom of the body tag following by initialization script.
-->
<script src="https://code.yesplz.ai/stylefilter/<RETAILER CODE>/<VERSION>/stylefilter.js"></script>
<script>
// Initialize Logger in the global area
window.yesplz.Logger.init();
</script>
</body>
  • <VERSION> can be latest or staging.

Initialize

This module requires initialization to track events.
Call it from a global area that applies to all pages.

// Option 1, initialize without user ID and profile
window.yesplz.Logger.init();

// Option 2, initialize with user ID and profile if it's already known
window.yesplz.Logger.init({
user_id: 'USER_ID', // unique identifier
user_pfopertires: { // optional user properties
name: 'USER_NAME', // user name,
custom_property1: '', // any custom propertires that you want to pass
custom_property2: '',
...
}
});

Identify User

If your application has a login system that you want to track users with, call setUser to update the user's identifier.

// When user logs in
window.yesplz.Logger.setUser('USER_ID', { // optional user properties
name: 'USER_NAME', // user name,
custom_property1: '', // any custom propertires that you want to pass
custom_property2: '',
...
});


Call reset() to clear data attributed to a user when that user logs out and the session is expired.

// When user logs out or session is expired
window.yesplz.Logger.reset();

Track Events

Add this code snippet to events like “Purchase” and any additional events that may track the core features of your product.
Events represent how users interact with your e-commerce site.

Track events using defined event types

Replace Purchase with an event type that makes sense for the situation. Check the below Event Types.

All events sent from the JavaScript library will be sent over HTTPS. ㅤ

Event Types

The following events are based on the GA E-commerce standard.

Event TypeDescriptionRequired Properties
ViewItemUser views a product detail page

(Previously ViewProduct)
currency: string
value: number
items: object[]
FavoriteProductUser marks a product as a favoriteid: string
(Product ID)
UnFavoriteProductUser removes a product from their favoritesid: string
(Product ID)
AddToCartUser adds a product to their shopping cartcurrency: string
value: number
items: object[]

id: string (Deprecated)
RemoveFromCartUser removes a product from their shopping cartcurrency: string
value: number
items: object[]

id: string (Deprecated)
PurchaseUser completes a purchase of a productcurrency: string
value: number
transaction_id: string
items: object[]

id: string (Deprecated)
ViewBrandUser views a brand pageid: string
(Brand name)
FavoriteBrandUser marks a brand as a favoriteid: string
(Brand name)
UnFavoriteBrandUser removes a brand from their favoritesid: string
(Brand name)

Event Parameters Details

info

Our event tracking follows the Google Analytics 4 E-commerce events standard for consistent data collection and reporting.

Common E-commerce Event Parameters

The following parameters are used across multiple e-commerce events (ViewItem, AddToCart, RemoveFromCart, Purchase):

NameTypeRequiredExample valueDescription
currencystringYes*USDCurrency of the items associated with the event, in 3-letter ISO 4217 format.

*If you set value then currency is required for revenue metrics to be computed accurately.
valuenumberYes*30.03The monetary value of the event.

*Set value to the sum of (price × quantity) for all items in items. Don't include shipping or tax.
*value is typically required for meaningful reporting. If you mark the event as a key event then it's recommended you set value.
*currency is required if you set value.
itemsArray<Item>YesSee belowThe items for the event. See items object schema below for details.
transaction_idstringYes*T_12345The unique identifier of a transaction.

*Required only for Purchase event.

items, items_USD object schema

NameTypeRequiredExample valueDescription
item_idstringYes*PRODUCT_SKU_7890The ID of the item.

*One of item_id or item_name is required.
item_namestringYes*Awesome T-ShirtThe name of the item.

*One of item_id or item_name is required.
pricenumberNo25.99The monetary unit price of the item, in units of the specified currency parameter.
If a discount applies to the item, set price to the discounted unit price and specify the unit price discount in the discount parameter.
quantitynumberNo2Item quantity.

If not set, quantity is set to 1.
affiliationstringNoMy Online StoreA product affiliation to designate a supplying company or brick and mortar store location.
Note: affiliation is only available at the item-scope.
couponstringNoSAVE20The coupon name/code associated with the item.

Event-level and item-level coupon parameters are independent.
discountnumberNo5.00The unit monetary discount value associated with the item.
indexnumberNo1The index/position of the item in a list.
item_brandstringNoBrandXThe brand of the item.
item_categorystringNoElectronicsThe category of the item. If used as part of a category hierarchy or taxonomy then this will be the first category.
item_category2stringNoSmartphonesThe second category hierarchy or additional taxonomy for the item.
item_category3stringNoAndroidThe third category hierarchy or additional taxonomy for the item.
item_category4stringNoFlagshipThe fourth category hierarchy or additional taxonomy for the item.
item_category5stringNoLarge ScreenThe fifth category hierarchy or additional taxonomy for the item.
item_list_idstringNohomepage_carouselThe ID of the list in which the item was presented to the user.

If set, event-level item_list_id is ignored.
If not set, event-level item_list_id is used, if present.
item_list_namestringNoHomepage CarouselThe name of the list in which the item was presented to the user.

If set, event-level item_list_name is ignored.
If not set, event-level item_list_name is used, if present.
item_variantstringNoblue-largeThe item variant or unique code or description for additional item details/options.

Usage Example

You can use the event types as follows:

// Example
const { ViewItem, AddToCart, Purchase } = window.yesplz.Logger.EventType;

// Track when user views a product detail page
window.yesplz.Logger.track(ViewItem, {
currency: 'USD',
value: 123.45,
items: [
{
item_id: 'SKU_12345',
item_name: 'Stan and Friends Tee',
price: 123.45,
quantity: 1
}
],
items_USD: [
{
item_id: 'SKU_12345',
item_name: 'Stan and Friends Tee',
price: 123.45,
quantity: 1
}
]
});

// Track when user adds item to cart
window.yesplz.Logger.track(AddToCart, {
currency: 'USD',
value: 123.45,
items: [
{
item_id: 'SKU_12345',
item_name: 'Stan and Friends Tee',
price: 123.45,
quantity: 1
}
],
items_USD: [
{
item_id: 'SKU_12345',
item_name: 'Stan and Friends Tee',
price: 123.45,
quantity: 1
}
]
});

// Track when user completes a purchase
window.yesplz.Logger.track(Purchase, {
currency: 'USD',
value: 123.45,
transaction_id: 'T_12345',
items: [
{
item_id: 'SKU_12345',
item_name: 'Stan and Friends Tee',
price: 123.45,
quantity: 1
}
],
items_USD: [
{
item_id: 'SKU_12345',
item_name: 'Stan and Friends Tee',
price: 123.45,
quantity: 1
}
]
});

Track events using custom event types

Replace click_some_button with a unique identifier for the event.

// Option 1, track a custom event
window.yesplz.Logger.track('click_some_button');

// Option 2, track a custom event with optional properties
window.yesplz.Logger.track('click_some_button', {
custom_property1: '',
custom_property2: '',
...
});


🥳 You’re ready to start using Logger! Should have any questions, let us know at hello@yesplz.ai