Skip to content

Google Tag Manager and Google Analytics

By default Bilberry Widgets will register analytics events by simply pushing to window.dataLayer. These events can be picked up by utilizing Google Tag Manager (GTM) on your website, which will forward events to Google Analytics.

We also support registering analytics events directly against Google Tag (GTAG), instead of through the default dataLayer/GTM.
Add the following line to your widgets configuration if you want to use GTAG: window.BilberryWidgetsGlobal.useGtag = true;

Analytics events are structured in a GA4/ecommerce compatible format, and will be automatically displayed correctly in Google Analytics.
See this link for details: https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm

In order for either the GTAG or GTM approach to work, make sure you’ve also added the appropriate (GTAG/GTM) code-snippet-setup to your website.

The easiest way (recommended) for you to get started is to simply use GTAG instead of the default GTM/dataLayer, by adding the config-option specified above. You don’t need to do anything else, events will be correctly registered and visible in your Google Analytics dashboard.

If you’ve decided to use the GTM approach, continue reading the next section (Configuring Google Tag Manager) for details on how to set up your GTM configuration.

Configuring Google Tag Manager

This section contains instructions on how to set up your GTM configuration.
Don’t follow this section if you’ve chosen the GTAG approach, as these steps are not required.

For compatibility/legacy reasons event-names are by default dispatched in the old Universal Analytics (UA) style, instead of the new Google Analytics 4 (GA4) style. In most cases you don’t want the default behavior (UA), and instead want the new GA4 style.
(GTAG already uses GA4-style by default, so this only applies when using GTM)

Add the following line to your widgets configuration to use the new GA4 style event-names:
window.BilberryWidgetsGlobal.useGtmGa4 = true;

In short, all you need to get started is to create two tags and a single trigger, as specified below.

Creating TRIGGER: Custom Event

  1. Select the Triggers section inside your Tag Manager account/dashboard.
  2. Click New to create a new trigger.
  3. Set Trigger Name = Events
  4. Set Trigger Type = Custom Event
  5. Set Event name = *
  6. Set This trigger fires on = All Custom Events
  7. Click Save.

Creating TAG (1): Google tag

  1. Select the Tags section inside your Tag Manager account/dashboard.
  2. Click New to create a new tag.
  3. Set Tag Name = Google Tag
  4. Set Tag Type= Google Tag
  5. Set Tag ID to the Measurement-ID/Tag-ID found in your Google Analytics account.
  6. Make sure Triggers for this tag has a single trigger Initialization - All Pages.
  7. Click Save.

Creating TAG (2): Google Analytics: GA4 Event

  1. Select the Tags section inside your Tag Manager account/dashboard.
  2. Click New to create a new tag.
  3. Set Tag Name = Google Analytics
  4. Set Tag Type= Google Analytics: GA4 Event
  5. Set Measurement ID to the Measurement-ID/Tag-ID found in your Google Analytics account.
  6. Set Event Name= {{Event}}
  7. Select/check-on the More Settings > Ecommerce > Send Ecommerce data option, and make sure Data source is set to Data Layer.
  8. Add a single Trigger for this tag, choose the trigger you created in the previous step.
  9. Click Save.

That’s it! Events should begin to appear in your Google Analytics account.
Since events are structured in a GA4/ecommerce compatible format, the data will automatically be displayed correctly in your analytics reports.

Technical details (advanced users)

For developers or digital marketers, this section provides:

  • Technical details about how our events are structured.
  • Code examples to illustrate exactly how we register events against GTM or GTAG.

Event list

This is how an exampleItem might look like:
(This object is referenced in the table further down)

const exampleItem = {
item_id: '123',
item_name: 'Example product',
item_category: 'Example category',
price: 5000,
quantity: 2,
currency: 'NOK',
coupon: 'EXAMPLE-CODE',
}
Event nameDetails/Data
add_to_cartAdd item to the shopping cart.
Data:
{ value: 1000, currency: 'NOK', items: [exampleItem, ...] }
remove_from_cartRemove an item from the shopping cart.
Data:
{ value: 1000, currency: 'NOK', items: [exampleItem, ...] }
view_itemRepresents information about a product that has been viewed.
Data:
{ value: 1000, currency: 'NOK', items: [exampleItem, ...] }
begin_checkoutWhen navigating to the checkout page with a summary of all items in the cart.
Data:
{ value: 1000, currency: 'NOK', items: [exampleItem, ...] }
set_checkout_stepWhere in the checkout process the user is. Here’s the following Steps:
- Package
- Extras
- Contact Info
- Payment
- Success
- Cancel
Data:
{ checkout_step: 1, checkout_step_title: 'Contact Info' }
Please note that the step-number could vary based on if extras are enabled or not.
purchaseRegister purchase after checkout-completion.
Data:
{ value: 1000, currency: 'NOK', items: [exampleItem, ...] }
loginUser logged in.

Data:
{ method: 'bilberry' }
add_payment_infoPayment-info has been added.
Data:
{ value: 1000, currency: 'NOK', coupon: 'EXAMPLE-COUPON' items: [exampleItem, ...] }

Examples/Snippets

These examples are only meant to give you an idea how bilberry widgets registers analytics events against GTAG or GTM. You are not meant to do this manually.

// Registering an event using GTAG.
// This uses the global gtag() function that is provided
// by the GTAG-setup-snippet.
window.gtag('event', 'add_to_cart', {
value: 3400, currency: 'NOK', items: [exampleItem, ...]
});
// Registering an event using GTM.
// This does a push to window.dataLayer[], which will be
// picked up by GTM.
window.dataLayer.push({
event: 'add_to_cart',
ecommerce: {
value: 3400, currency: 'NOK', items: [exampleItem, ...]
}
});