Skip to content

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:

  1. Create a Custom Event trigger with the event name c2b_widget_event.
  2. Create Data Layer Variables for the fields you need, for example action or product.ean (see the event list).
  3. Use them in a Google Analytics event tag fired by this trigger. To track only some events, add a condition on action to the trigger.

Event list ​

Every event contains the following fields:

FieldDescription
serviceThe widget that sent the event: widget (Standard Widget) or multiproductWidget (MultiProduct Widget)
actionThe event name, from the table below
idThe widget key: WIDGET_ID (Standard Widget) or MULTIPRODUCT_WIDGET_ID (MultiProduct Widget)

Depending on the event, it also contains:

actionSent whenAdditional fields
printThe widget opens: when the visitor clicks the button, or when the page loads in inline auto-open modeproduct (Standard Widget only)
select_productThe visitor selects a product (MultiProduct Widget only)product
select_locationThe visitor's location is set, automatically or by the visitorlocation
print_retail_outletsRetail outlets are displayed. Sent once per distribution type, and only if at least one retail outlet is founddistribution_type, retail_outlets, product
print_delivery_retailersRetailers offering home delivery are displayeddistribution_type (always delivery), retail_outlets, product
select_retail_outletThe visitor selects a retail outletdistribution_type, retail_outlet, product

Event fields ​

product ​

FieldDescription
nameProduct name
raw_packagingProduct packaging, for example 800 g
eanEAN code as 14 digits: a 13-digit EAN gets a leading 0
upcUPC code
referenceProduct reference

location ​

FieldDescription
addressFull address
street, houseNumberStreet and house number
zipcode, cityPostal code and city
county, stateCounty, and state or region
country, countryCodeCountry name and code
lat, lngLatitude 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:

FieldDescription
retailer_nameRetailer name
nameRetail outlet name
address, zipcode, city, stateAddress of the retail outlet
lat, lngLatitude and longitude

distribution_type ​

ValueDescription
storePurchase in store
driveClick & Collect
deliveryHome 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"
  }
}