Widget events for your analytics
Click2Buy tracks widget usage automatically: statistics are available in our back office (ask your Customer Success Manager for more details).
To also track widget events in your own analytics tool (Google Analytics, for example), listen to the c2b:widget:tracking event. Our script dispatches it on the window of your page for each widget event, with the event data in event.detail.
INFO
This page covers the events of the Standard and MultiProduct widgets. The Shop sends events too, listed on its page. The Cart Widget and the Store Locator only have Click2Buy's native tracking.
Add the listener scripts below to the pages that display a widget, in your own JavaScript or in your tag manager.
Log events in the browser console
To see the events while testing, paste this code into the browser console on your website, then use the widget: each event is logged as it happens.
js
window.addEventListener('c2b:widget:tracking', function (event) {
console.log('C2B widget event:', event.detail)
})Send events to Google Analytics
This script sends every widget event to the dataLayer of Google Tag Manager, as a c2b_widget_event event with the event data:
js
window.addEventListener('c2b:widget:tracking', function (event) {
window.dataLayer = window.dataLayer || []
window.dataLayer.push({ event: 'c2b_widget_event', ...event.detail })
})Then, in Google Tag Manager:
- Create a Custom Event trigger with the event name
c2b_widget_event. - Create Data Layer Variables for the fields you need, for example
actionorproduct.ean(see the event list). - Use them in a Google Analytics event tag fired by this trigger. To track only some events, add a condition on
actionto the trigger.
Event list
Every event contains the following fields:
| Field | Description |
|---|---|
service | The widget that sent the event: widget (Standard Widget) or multiproductWidget (MultiProduct Widget) |
action | The event name, from the table below |
id | The widget key: WIDGET_ID (Standard Widget) or MULTIPRODUCT_WIDGET_ID (MultiProduct Widget) |
Depending on the event, it also contains:
action | Sent when | Additional fields |
|---|---|---|
print | The widget opens: when the visitor clicks the button, or when the page loads in inline auto-open mode | product (Standard Widget only) |
select_product | The visitor selects a product (MultiProduct Widget only) | product |
select_location | The visitor's location is set, automatically or by the visitor | location |
print_retail_outlets | Retail outlets are displayed. Sent once per distribution type, and only if at least one retail outlet is found | distribution_type, retail_outlets, product |
print_delivery_retailers | Retailers offering home delivery are displayed | distribution_type (always delivery), retail_outlets, product |
select_retail_outlet | The visitor selects a retail outlet | distribution_type, retail_outlet, product |
Event fields
product
| Field | Description |
|---|---|
name | Product name |
raw_packaging | Product packaging, for example 800 g |
ean | EAN code as 14 digits: a 13-digit EAN gets a leading 0 |
upc | UPC code |
reference | Product reference |
location
| Field | Description |
|---|---|
address | Full address |
street, houseNumber | Street and house number |
zipcode, city | Postal code and city |
county, state | County, and state or region |
country, countryCode | Country name and code |
lat, lng | Latitude and longitude |
Depending on how the location was set (IP address, browser geolocation, address input, etc.), some fields can be empty.
retail_outlet
retail_outlet contains one retail outlet, and retail_outlets a list of them. Each retail outlet has the following fields:
| Field | Description |
|---|---|
retailer_name | Retailer name |
name | Retail outlet name |
address, zipcode, city, state | Address of the retail outlet |
lat, lng | Latitude and longitude |
distribution_type
| Value | Description |
|---|---|
store | Purchase in store |
drive | Click & Collect |
delivery | Home delivery |
Example event
The event.detail of a select_retail_outlet event from a Standard Widget:
json
{
"service": "widget",
"action": "select_retail_outlet",
"id": "WIDGET_ID",
"distribution_type": "store",
"retail_outlet": {
"retailer_name": "Retailer",
"name": "Retailer Lille Centre",
"address": "1 rue Nationale",
"zipcode": "59000",
"city": "Lille",
"state": "Hauts-de-France",
"lat": 50.6365,
"lng": 3.0635
},
"product": {
"name": "Product name",
"raw_packaging": "800 g",
"ean": "03017620425035",
"upc": null,
"reference": "ref-001"
}
}