Skip to main content

Enhanced ecommerce tracking

danger

This plugin has been deprecated and superseded by the Snowplow ecommerce plugin. We highly recommend using this newer plugin, which is more fully featured and allows you to use the DBT model we provide.

This plugin is based on Google Analytics' Enhanced Ecommerce package. For more information on the Enhanced Ecommerce functions please see the Google Analytics documentation.

Enhanced ecommerce events must be manually tracked.

Install plugin

Tracker DistributionIncluded
sp.js
sp.lite.js

Download:

Download from GitHub Releases (Recommended)Github Releases (plugins.umd.zip)
Available on jsDelivrjsDelivr (latest)
Available on unpkgunpkg (latest)

Note: The links to the CDNs above point to the current latest version. You should pin to a specific version when integrating this plugin on your website if you are using a third party CDN in production.

window.snowplow('addPlugin',
"https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-enhanced-ecommerce@latest/dist/index.umd.min.js",
["snowplowEnhancedEcommerce", "EnhancedEcommercePlugin"]
);

Event

The enhanced ecommerce plugin is based around the EnhancedEcommerceAction event, to which can be added the Action, Impression, Product and Promo context entities. The context entities must be added first, before the event is tracked.

Use the trackEnhancedEcommerceAction method to track a GA Enhanced Ecommerce Action. When this function is called all of the added Ecommerce context entities are attached to this action and flushed from the tracker.

NameRequired?Type
actionYesstring

The allowed actions:

  • click
  • detail
  • add
  • remove
  • checkout
  • checkout_option
  • purchase
  • refund
  • promo_click
  • view

Adding an action using Google Analytics:

ga('ec:setAction', 'refund', {
'id': 'T12345'
});

Adding an action using Snowplow:

snowplow('addEnhancedEcommerceActionContext', {
id: 'T12345'
});
snowplow('trackEnhancedEcommerceAction', {
action: 'refund'
});

Context entities

The enhanced ecommerce context entities are specific to this plugin, and cannot be added to any other event types.

Action

Use the addEnhancedEcommerceActionContext method to add a GA Enhanced Ecommerce Action Context to the Tracker:

NameRequired?Type
idYesstring
affiliationNostring
revenueNonumber OR string
taxNonumber OR string
shippingNonumber OR string
couponNostring
listNostring
stepNointeger OR string
optionNostring
currencyNostring

Adding an action using Google Analytics:

ga('ec:setAction', 'purchase', {
'id': 'T12345',
'affiliation': 'Google Store - Online',
'revenue': '37.39',
'tax': '2.85',
'shipping': '5.34',
'coupon': 'SUMMER2013'
});
note

The action type is passed with the action context in the Google Analytics example. We have separated this by asking you to call the trackEnhancedEcommerceAction function to actually send the context and the action.

Adding an action using Snowplow:

snowplow('addEnhancedEcommerceActionContext', {
id: 'T12345',
affiliation: 'Google Store - Online',
revenue: '37.39', // Can also pass as number
tax: '2.85', // Can also pass as number
shipping: '5.34', // Can also pass as number
coupon: 'WINTER2016'
});
``
</TabItem>
<TabItem value="browser" label="Browser (npm)">

```javascript
addEnhancedEcommerceActionContext({
id: 'T12345',
affiliation: 'Google Store - Online',
revenue: '37.39', // Can also pass as number
tax: '2.85', // Can also pass as number
shipping: '5.34', // Can also pass as number
coupon: 'WINTER2016'
});

Impression

Use the addEnhancedEcommerceImpressionContext method to add a GA Enhanced Ecommerce Impression Context to the Tracker:

NameRequired?Type
idYesstring
nameNostring
listNostring
brandNostring
categoryNostring
variantNostring
positionNointeger OR string
priceNonumber OR string
currencyNostring

Adding an impression using Google Analytics:

ga('ec:addImpression', {
'id': 'P12345',
'name': 'Android Warhol T-Shirt',
'list': 'Search Results',
'brand': 'Google',
'category': 'Apparel/T-Shirts',
'variant': 'Black',
'position': 1
});

Adding an impression using Snowplow:

snowplow('addEnhancedEcommerceImpressionContext', {
id: 'P12345',
name: 'Android Warhol T-Shirt',
list: 'Search Results',
brand: 'Google',
category: 'Apparel/T-Shirts',
variant: 'Black',
position: 1
});

Product

Use the addEnhancedEcommerceProductContext method to add a GA Enhanced Ecommerce Product Field Context:

NameRequired?Type
idYesstring
nameNostring
listNostring
brandNostring
categoryNostring
variantNostring
priceNonumber OR string
quantityNointeger OR string
couponNostring
positionNointeger OR string
currencyNostring

Adding a product using Google Analytics:

ga('ec:addProduct', {
'id': 'P12345',
'name': 'Android Warhol T-Shirt',
'brand': 'Google',
'category': 'Apparel/T-Shirts',
'variant': 'Black',
'position': 1
});

Adding a product using Snowplow:

snowplow('addEnhancedEcommerceProductContext', {
id: 'P12345',
name: 'Android Warhol T-Shirt',
list: 'Search Results',
brand: 'Google',
category: 'Apparel/T-Shirts',
variant: 'Black',
quantity: 1
});

Promo

Use the addEnhancedEcommercePromoContext method to add a GA Enhanced Ecommerce Promotion Field Context:

NameRequired?Type
idYesstring
nameNostring
creativeNostring
positionNostring
currencyNostring

Adding a promotion using Google Analytics:

ga('ec:addPromo', {
'id': 'PROMO_1234',
'name': 'Summer Sale',
'creative': 'summer_banner2',
'position': 'banner_slot1'
});

Adding a promotion using Snowplow:

snowplow('addEnhancedEcommercePromoContext', {
id: 'PROMO_1234', // The Promotion ID
name: 'Summer Sale', // The name
creative: 'summer_banner2', // The name of the creative
position: 'banner_slot1' // The position
});