Converts and validates humanly understandable Enhanced E-commerce params into Measurement Protocol. Friends with universal-analytics.
var gampee = require("gampee"),
ga = require("universal-analytics");
var ecommerceParams = gampee({
"type": "impression",
"list": "search",
"products": [
{ "id": "shirtM", "name": "Nice T-Shirt (M)", "position": 1 },
{ "id": "shirtXL", "name": "Nice T-Shirt (XL)", "position": 2 }
],
"currency": "EUR"
});
assert.equal(ecommerceParams, {
"il0nm": "search",
"il0pi0id": "shirtM",
"il0pi0nm": "Nice T-Shirt (M)",
"il0pi0ps": 1,
"il0pi1id": "shirtXL",
"il0pi1nm": "Nice T-Shirt (XL)",
"il0pi1ps": 2,
"cu": "EUR"
});
// send together with a pageview
var ua = ga("UA-00000000-0", "5bbb81ff-0757-44e0-8fcb-f263d982b95a", { debug: true });
ua.pageview(_.merge({ dp: "/search?q=some+product", cd20: "one", cm20: "two" }, ecommerceParams));
- Custom product dimensions/metrics
promo
andpromo_click
gampee( EcommerceAction action, [function onValidationError] )
gampee( EcommerceAction[] actionList, [function onValidationError] )
EcommerceAction
is an object with a required type
property. type
can be either an impression
or one of ecommerce
product actions:
click
, detail
, add
, remove
, purchase
, refund
, checkout
, checkout_option
. Each data item should also
have a list of Product[] products
.
You can send multiple items with impressions (e.g. when there are multiple lists of products on the page), but only one product action with each analytics hit (event, pageview, etc).
If onValidationError
is passed in (default: void
), it will be called with details of every validation warning, e.g.
gampee( myParams, console.warn.bind(console));
See the table below for required/optional/allowed properties of EcommerceAction
and Product
.
Note that although documentation says all hit types are allowed, the product information will be discarded if sent with
transaction
hit type (and probably some others). We have only tried testing full information with pageview
and
event
hit types.
This roughly mirrors the ecommerce.js API.
type |
||||||
---|---|---|---|---|---|---|
impression |
click , detail |
add , remove |
purchase , refund |
checkout , checkout_option |
||
currency
Currency Code |
opt | opt | opt | opt | opt | |
list
Product Action List, Product Impression List Name |
opt | opt | opt | |||
id
Transaction ID |
req | |||||
affiliation
Transaction Affiliation |
opt | |||||
revenue
Transaction Revenue |
opt | |||||
tax
Transaction Tax |
opt | |||||
shipping
Transaction Shipping |
opt | |||||
coupon
Coupon Code |
opt | |||||
step
Checkout Step |
opt | |||||
option
Checkout Step Option |
opt | |||||
products[] |
||||||
id
Product SKU |
req | req | req | req | req | |
name
Product Name |
req | req | req | req | req | |
brand
Product Brand |
opt | opt | opt | opt | opt | |
category
Product Category |
opt | opt | opt | opt | opt | |
variant
Product Variant |
opt | opt | opt | opt | opt | |
price
Product Price |
opt | opt | opt | opt | opt | |
position
Product Position |
opt | opt | ||||
coupon
Product Coupon Code |
opt | opt | opt | opt | ||
quantity
Product Quantity |
opt | opt | opt |