Socket
Socket
Sign inDemoInstall

universal-ga

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.2.0

34

lib/analytics.js
/*!
* universal-ga v1.1.0
* universal-ga v1.2.0
* https://github.com/daxko/universal-ga

@@ -195,2 +195,34 @@ *

return this;
},
// https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce
initializeEcommerce: function() {
this.plugin('ecommerce');
},
ecAddTransaction: function(transaction) {
if(!transaction || !transaction.id){
warn('addTransaction: `transaction` is required and needs an `id`.');
return;
}
_set.call(this, 'ecommerce:addTransaction', transaction);
return this;
},
ecAddItem: function(productItem) {
if(!productItem || !productItem.id || !productItem.name){
warn('addItem: `productItem` is required and needs an `id` and a `name`.');
return;
}
_set.call(this, 'ecommerce:addItem', productItem);
return this;
},
ecSend: function() {
_set.call(this, 'ecommerce:send');
},
ecClear: function () {
_set.call(this, 'ecommerce:clear');
}

@@ -197,0 +229,0 @@

5

lib/analytics.min.js
/*!
* universal-ga v1.1.0
* universal-ga v1.2.0
* https://github.com/daxko/universal-ga

@@ -8,2 +8,3 @@ *

*/
!function(a){"use strict";function b(a){console.warn("[analytics]",a)}function c(){for(var a=[],b=arguments.length,c=0;c<b;c++)a.push(arguments[c]);for(;"undefined"==typeof a[a.length-1];)a.pop();this._namespace&&(a[0]=this._namespace+"."+a[0],this._namespace=null),window&&"function"==typeof window.ga&&window.ga.apply(void 0,a)}var d=function(){return this};d.prototype={initialize:function(a,b){var c="https://www.google-analytics.com/";"object"==typeof a&&(b=a),b=b||{},b.debug?(c+="analytics_debug.js",delete b.debug):c+="analytics.js",function(a,b,c,d,e,f,g){a.GoogleAnalyticsObject=e,a[e]=a[e]||function(){(a[e].q=a[e].q||[]).push(arguments)},a[e].l=1*new Date,f=b.createElement(c),g=b.getElementsByTagName(c)[0],f.async=1,f.src=d,g.parentNode.insertBefore(f,g)}(window,document,"script",c,"ga"),a&&(b="{}"===JSON.stringify(b)?void 0:b,this.create(a,b))},create:function(a,d){return a?void c.call(this,"create",a,"auto",d):void b("tracking id is required to initialize.")},name:function(a){var b=new d;return b._namespace=a,b},set:function(a,d){return a&&a.length?(c.call(this,"set",a,d),this):void b("set: `key` is required.")},plugin:function(a,d){return a&&a.length?(c.call(this,"require",a,d),this):void b("plugin: `name` is required.")},pageview:function(a,b){return c.call(this,"send","pageview",a,b),this},screenview:function(a,d){return a?(d=d||{},d.screenName=a,c.call(this,"send","screenview",d),this):void b("screenview: `screenName` is required.")},event:function(a,d,e){return a&&d?(e&&"undefined"!=typeof e.eventValue&&"number"!=typeof e.eventValue&&(b("event: expected `options.eventValue` to be a Number."),e.eventValue=void 0),e&&e.nonInteraction&&"boolean"!=typeof e.nonInteraction&&(b("event: expected `options.nonInteraction` to be a boolean."),e.nonInteraction=!1),c.call(this,"send","event",a,d,e),this):void b("event: both `category` and `action` are required.")},timing:function(a,d,e,f){return a&&d&&"undefined"!=typeof e?"number"!=typeof e?b("event: expected `timingValue` to be a Number."):c.call(this,"send","timing",a,d,e,f):b("timing: `timingCategory`, `timingVar`, and `timingValue` are required."),this},exception:function(a,b){return c.call(this,"send","exception",{exDescription:a,exFatal:!!b}),this},custom:function(a,d){return/(dimension|metric)[0-9]+/i.test(a)?(c.call(this,"set",a,d),this):void b("custom: key must match dimension[0-9]+ or metric[0-9]+")}};var e=new d;"function"==typeof define&&define.amd?define([],function(){return e}):"object"==typeof module&&"object"==typeof module.exports?module.exports=e:a.analytics=e}(this);
!function(a){"use strict";function b(a){console.warn("[analytics]",a)}function c(){for(var a=[],b=arguments.length,c=0;c<b;c++)a.push(arguments[c]);for(;void 0===a[a.length-1];)a.pop();this._namespace&&(a[0]=this._namespace+"."+a[0],this._namespace=null),window&&"function"==typeof window.ga&&window.ga.apply(void 0,a)}var d=function(){return this};d.prototype={initialize:function(a,b){var c="https://www.google-analytics.com/";"object"==typeof a&&(b=a),b=b||{},b.debug?(c+="analytics_debug.js",delete b.debug):c+="analytics.js",function(a,b,c,d,e,f,g){a.GoogleAnalyticsObject=e,a[e]=a[e]||function(){(a[e].q=a[e].q||[]).push(arguments)},a[e].l=1*new Date,f=b.createElement(c),g=b.getElementsByTagName(c)[0],f.async=1,f.src=d,g.parentNode.insertBefore(f,g)}(window,document,"script",c,"ga"),a&&(b="{}"===JSON.stringify(b)?void 0:b,this.create(a,b))},create:function(a,d){if(!a)return void b("tracking id is required to initialize.");c.call(this,"create",a,"auto",d)},name:function(a){var b=new d;return b._namespace=a,b},set:function(a,d){return a&&a.length?(c.call(this,"set",a,d),this):void b("set: `key` is required.")},plugin:function(a,d){return a&&a.length?(c.call(this,"require",a,d),this):void b("plugin: `name` is required.")},pageview:function(a,b){return c.call(this,"send","pageview",a,b),this},screenview:function(a,d){return a?(d=d||{},d.screenName=a,c.call(this,"send","screenview",d),this):void b("screenview: `screenName` is required.")},event:function(a,d,e){return a&&d?(e&&void 0!==e.eventValue&&"number"!=typeof e.eventValue&&(b("event: expected `options.eventValue` to be a Number."),e.eventValue=void 0),e&&e.nonInteraction&&"boolean"!=typeof e.nonInteraction&&(b("event: expected `options.nonInteraction` to be a boolean."),e.nonInteraction=!1),c.call(this,"send","event",a,d,e),this):void b("event: both `category` and `action` are required.")},timing:function(a,d,e,f){return a&&d&&void 0!==e?"number"!=typeof e?b("event: expected `timingValue` to be a Number."):c.call(this,"send","timing",a,d,e,f):b("timing: `timingCategory`, `timingVar`, and `timingValue` are required."),this},exception:function(a,b){return c.call(this,"send","exception",{exDescription:a,exFatal:!!b}),this},custom:function(a,d){return/(dimension|metric)[0-9]+/i.test(a)?(c.call(this,"set",a,d),this):void b("custom: key must match dimension[0-9]+ or metric[0-9]+")},initializeEcommerce:function(){this.plugin("ecommerce")},ecAddTransaction:function(a){return a&&a.id?(c.call(this,"ecommerce:addTransaction",a),this):void b("addTransaction: `transaction` is required and needs an `id`.")},ecAddItem:function(a){return a&&a.id&&a.name?(c.call(this,"ecommerce:addItem",a),this):void b("addItem: `productItem` is required and needs an `id` and a `name`.")},ecSend:function(){c.call(this,"ecommerce:send")},ecClear:function(){c.call(this,"ecommerce:clear")}};var e=new d;"function"==typeof define&&define.amd?define([],function(){return e}):"object"==typeof module&&"object"==typeof module.exports?module.exports=e:a.analytics=e}(this);
{
"name": "universal-ga",
"version": "1.1.0",
"version": "1.2.0",
"description": "Universal Google Analytics module for node",

@@ -5,0 +5,0 @@ "main": "lib/analytics.js",

@@ -9,2 +9,3 @@ # universal-ga

* Plugins
* Pageviews

@@ -16,2 +17,3 @@ * Screenviews

* Custom Dimensions/Metrics
* Ecommerce Tracking

@@ -209,3 +211,3 @@ # Install

```js
analytics.event('category', 'action', { eventValue: 123 });
analytics.event('category', 'action', { eventLabel: 'label' });
```

@@ -265,1 +267,71 @@

```
#### analytics.ecAddTransaction( *transaction* )
|Name|Description|
|-----|-----|
|transaction| `object` a transaction.
An ecommerce transaction represents the entire transaction that occurs on your site. See[ecommerce documentation](https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce) for more details. A transaction `object` can consist of the following objects:
|Name|Type|Description|
|-----|-----|-----|
|id| `text`| The transaction ID. (e.g. 1234).
|affiliation| `text`| (optional) The store or affiliation from which this transaction occurred (e.g. Acme Clothing).
|revenue| `currency`| (optional) No Specifies the total revenue or grand total associated with the transaction (e.g. 11.99). This value may include shipping, tax costs, or other adjustments to total revenue that you want to include as part of your revenue calculations.
|shipping| `currency`| (optional) No Specifies the total shipping cost of the transaction. (e.g. 5).
|tax| `currency`| (optional) No Specifies the total tax of the transaction. (e.g. 1.29).
###### Example
```js
let transaction = {
'id': '1234', // Transaction ID. Required.
'affiliation': 'Acme Clothing', // Affiliation or store name.
'revenue': '11.99', // Grand Total.
'shipping': '5', // Shipping.
'tax': '1.29' // Tax.
};
analytics.ecAddTransaction(transaction);
```
#### analytics.ecAddItem( *productItem* )
|Name|Description|
|-----|-----|
|productItem| `object` individual product.
An item represents the individual products that were in the shopping cart, and contains the following values::
|Name|Type|Description|
|-----|-----|-----|
|id| `text`| The transaction ID. This ID is what links items to the transactions to which they belong. (e.g. 1234).
|name| `text`| The item name. (e.g. Fluffy Pink Bunnies).
|sku| `text`| (optional) Specifies the SKU or item code. (e.g. SKU47).
|category| `text`| (optional) The category to which the item belongs (e.g. Party Toys).
|price| `text`| (optional) The individual, unit, price for each item. (e.g. 11.99).
|quantity| `integer`| (optional) The number of units purchased in the transaction. If a non-integer value is passed into this field (e.g. 1.5), it will be rounded to the closest integer value.
###### Example
```js
let productItem = {
'id': '1234', // Transaction ID. Required.
'name': 'Fluffy Pink Bunnies', // Product name. Required.
'sku': 'DD23444', // SKU/code.
'category': 'Party Toys', // Category or variation.
'price': '11.99', // Unit price.
'quantity': '1' // Quantity.
};
analytics.ecAddItem(productItem);
```
#### analytics.ecSend()
Finally, once you have configured all your ecommerce data in the shopping cart, you send the data to Google Analytics using the ecSend command.
#### analytics.ecClear()
If you need to manually clear the shopping cart of all transactions and items, you use this command.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc