1.0.1 • Published 9 years ago

gampee v1.0.1

Weekly downloads
156
License
MIT
Repository
github
Last release
9 years ago

gampee

Build Status

Converts and validates humanly understandable Enhanced E-commerce params into Measurement Protocol. Friends with universal-analytics.

Example

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));

Unsupported Measurement Protocol options

  • Custom product dimensions/metrics
  • promo and promo_click

Usage

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.

Params

This roughly mirrors the ecommerce.js API.

Google's documentation

1.0.1

9 years ago

1.0.0

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago