@analytics/google-analytics
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.4.1](https://github.com/DavidWells/analytics/compare/@analytics/google-analytics@0.4.0...@analytics/google-analytics@0.4.1) (2020-07-30) | ||
**Note:** Version bump only for package @analytics/google-analytics | ||
# [0.4.0](https://github.com/DavidWells/analytics/compare/@analytics/google-analytics@0.3.1...@analytics/google-analytics@0.4.0) (2020-05-12) | ||
@@ -8,0 +16,0 @@ |
@@ -79,2 +79,3 @@ var analyticsGa = (function (exports) { | ||
* @param {string} [pluginConfig.customScriptSrc] - Custom URL for google analytics script, if proxying calls | ||
* @param {object} [pluginConfig.cookieConfig] - Additional cookie properties for configuring the [ga cookie](https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings) | ||
* @return {*} | ||
@@ -125,10 +126,9 @@ * @example | ||
if (!loadedInstances[instanceName]) { | ||
var gaConfig = { | ||
var gaConfig = _objectSpread({ | ||
cookieDomain: config.domain || 'auto', | ||
siteSpeedSampleRate: config.siteSpeedSampleRate || 1, | ||
sampleRate: config.sampleRate || 100, | ||
allowLinker: true // useAmpClientId: config.useAmpClientId | ||
allowLinker: true | ||
}, config.cookieConfig); | ||
}; | ||
if (instanceName) { | ||
@@ -135,0 +135,0 @@ gaConfig.name = instanceName; |
@@ -1,1 +0,1 @@ | ||
var analyticsGa=function(e){"use strict";function p(i){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(e){var n,t,a;n=i,a=r[t=e],t in n?Object.defineProperty(n,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[t]=a})}return i}var t={trackingId:null,debug:!1,anonymizeIp:!1,customDimensions:{},resetCustomDimensionsOnPage:[],setCustomDimensionsToPage:!0},y={};function n(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},v=!1,n=c(e),d=n.instanceName,m=n.instancePrefix;return{name:"google-analytics",config:p({},t,e),initialize:function(e){var n=e.config,t=e.instance;if(!n.trackingId)throw new Error("No GA trackingId defined");var a,i,r,o,c,s,l,g=n.customScriptSrc||"https://www.google-analytics.com/analytics.js";if(h(g)&&(a=window,i=document,r="script",o=g,c="ga",a.GoogleAnalyticsObject=c,a.ga=a.ga||function(){(a.ga.q=a.ga.q||[]).push(arguments)},a.ga.l=1*new Date,s=i.createElement(r),l=i.getElementsByTagName(r)[0],s.async=1,s.src=o,l.parentNode.insertBefore(s,l)),!y[d]){var u={cookieDomain:n.domain||"auto",siteSpeedSampleRate:n.siteSpeedSampleRate||1,sampleRate:n.sampleRate||100,allowLinker:!0};d&&(u.name=d),ga("create",n.trackingId,u),n.debug&&(ga("".concat(m,"set"),"sendHitTask",null),window.ga_debug={trace:!0}),n.anonymizeIp&&ga("".concat(m,"set"),"anonymizeIp",!0);var f=(t.user()||{}).traits||{};if(Object.keys(f).length){var v=w(f,n);ga("".concat(m,"set"),v)}y[d]=!0}},page:function(e){var n=e.payload,t=e.config,a=e.instance,i=n.properties,r=t.resetCustomDimensionsOnPage,o=t.customDimensions,c=a.getState("context.campaign");if(!h()){if(r&&r.length){var s=r.reduce(function(e,n){return o[n]&&(e[o[n]]=null),e},{});Object.keys(s).length&&ga("".concat(m,"set"),s)}var l=i.path||document.location.pathname,g={page:l,title:i.title,location:i.url},u={page:l,title:i.title};i.referrer!==document.referrer&&(u.referrer=i.referrer);var f=p({},g,b(c),k(i,t,m));ga("".concat(m,"set"),u),v&&delete f.location,ga("".concat(m,"send"),"pageview",f),v=!0}},track:function(e){var n=e.payload,t=e.config,a=e.instance,i=n.properties,r=n.event,o=i.label,c=i.value;s({hitType:"event",event:r,label:o,category:i.category||"All",value:c,nonInteraction:i.nonInteraction,campaign:a.getState("context.campaign")},t,n)},identify:function(e){var n=e.payload,t=e.config;a(n.userId,n.traits,t)},loaded:function(){return!!window.gaplugins}}}function h(e){return e?(n=e,t=document.querySelectorAll("script[src]"),!Object.keys(t).filter(function(e){return(t[e].src||"")===n}).length):"undefined"==typeof ga;var n,t}function c(e){var n=e.instanceName;return{instancePrefix:n?"".concat(n,"."):"",instanceName:n}}function s(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},t=2<arguments.length?arguments[2]:void 0;if(!h()){var a,i=c(n).instancePrefix,r={hitType:e.hitType||"event",eventAction:e.event,eventLabel:e.label,eventCategory:e.category||"All",nonInteraction:void 0!==e.nonInteraction&&!!e.nonInteraction};e.value&&(r.eventValue=!(a=e.value)||a<0?0:Math.round(a));var o=p({},r,b(e),k(t.properties,n,i));return ga("".concat(i,"send"),"event",o),o}}function b(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n={},t=e.name,a=e.source,i=e.medium,r=e.content,o=e.keyword;return t&&(n.campaignName=t),a&&(n.campaignSource=a),i&&(n.campaignMedium=i),r&&(n.campaignContent=r),o&&(n.campaignKeyword=o),n}function w(i){var r=(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).customDimensions;return Object.keys(r).reduce(function(e,n){var t=r[n],a=function(e,n,t,a,i){for(n=n.split?n.split("."):n,a=0;a<n.length;a++)e=e?e[n[a]]:i;return e===i?t:e}(i,n)||i[n];return"boolean"==typeof a&&(a=a.toString()),(a||0===a)&&(e[t]=a),e},{})}function k(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=1<arguments.length?arguments[1]:void 0,t=2<arguments.length?arguments[2]:void 0,a=w(e,n);return Object.keys(a).length?n.setCustomDimensionsToPage?(ga("".concat(t,"set"),a),{}):a:{}}function a(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(!h()){var a=c(t).instancePrefix;if(e&&ga("".concat(a,"set"),"userId",e),Object.keys(n).length){var i=w(n,t);ga("".concat(a,"set"),i)}}}var i=n,r=n,o=s,l=a;return e.default=i,e.init=r,e.identify=l,e.track=o,e.page=void 0,e.initialize=void 0,e}({}); | ||
var analyticsGa=function(e){"use strict";function p(i){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(e){var n,t,a;n=i,a=r[t=e],t in n?Object.defineProperty(n,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[t]=a})}return i}var t={trackingId:null,debug:!1,anonymizeIp:!1,customDimensions:{},resetCustomDimensionsOnPage:[],setCustomDimensionsToPage:!0},y={};function n(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},v=!1,n=c(e),d=n.instanceName,m=n.instancePrefix;return{name:"google-analytics",config:p({},t,e),initialize:function(e){var n=e.config,t=e.instance;if(!n.trackingId)throw new Error("No GA trackingId defined");var a,i,r,o,c,s,l,g=n.customScriptSrc||"https://www.google-analytics.com/analytics.js";if(h(g)&&(a=window,i=document,r="script",o=g,c="ga",a.GoogleAnalyticsObject=c,a.ga=a.ga||function(){(a.ga.q=a.ga.q||[]).push(arguments)},a.ga.l=1*new Date,s=i.createElement(r),l=i.getElementsByTagName(r)[0],s.async=1,s.src=o,l.parentNode.insertBefore(s,l)),!y[d]){var u=p({cookieDomain:n.domain||"auto",siteSpeedSampleRate:n.siteSpeedSampleRate||1,sampleRate:n.sampleRate||100,allowLinker:!0},n.cookieConfig);d&&(u.name=d),ga("create",n.trackingId,u),n.debug&&(ga("".concat(m,"set"),"sendHitTask",null),window.ga_debug={trace:!0}),n.anonymizeIp&&ga("".concat(m,"set"),"anonymizeIp",!0);var f=(t.user()||{}).traits||{};if(Object.keys(f).length){var v=w(f,n);ga("".concat(m,"set"),v)}y[d]=!0}},page:function(e){var n=e.payload,t=e.config,a=e.instance,i=n.properties,r=t.resetCustomDimensionsOnPage,o=t.customDimensions,c=a.getState("context.campaign");if(!h()){if(r&&r.length){var s=r.reduce(function(e,n){return o[n]&&(e[o[n]]=null),e},{});Object.keys(s).length&&ga("".concat(m,"set"),s)}var l=i.path||document.location.pathname,g={page:l,title:i.title,location:i.url},u={page:l,title:i.title};i.referrer!==document.referrer&&(u.referrer=i.referrer);var f=p({},g,b(c),k(i,t,m));ga("".concat(m,"set"),u),v&&delete f.location,ga("".concat(m,"send"),"pageview",f),v=!0}},track:function(e){var n=e.payload,t=e.config,a=e.instance,i=n.properties,r=n.event,o=i.label,c=i.value;s({hitType:"event",event:r,label:o,category:i.category||"All",value:c,nonInteraction:i.nonInteraction,campaign:a.getState("context.campaign")},t,n)},identify:function(e){var n=e.payload,t=e.config;a(n.userId,n.traits,t)},loaded:function(){return!!window.gaplugins}}}function h(e){return e?(n=e,t=document.querySelectorAll("script[src]"),!Object.keys(t).filter(function(e){return(t[e].src||"")===n}).length):"undefined"==typeof ga;var n,t}function c(e){var n=e.instanceName;return{instancePrefix:n?"".concat(n,"."):"",instanceName:n}}function s(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},t=2<arguments.length?arguments[2]:void 0;if(!h()){var a,i=c(n).instancePrefix,r={hitType:e.hitType||"event",eventAction:e.event,eventLabel:e.label,eventCategory:e.category||"All",nonInteraction:void 0!==e.nonInteraction&&!!e.nonInteraction};e.value&&(r.eventValue=!(a=e.value)||a<0?0:Math.round(a));var o=p({},r,b(e),k(t.properties,n,i));return ga("".concat(i,"send"),"event",o),o}}function b(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n={},t=e.name,a=e.source,i=e.medium,r=e.content,o=e.keyword;return t&&(n.campaignName=t),a&&(n.campaignSource=a),i&&(n.campaignMedium=i),r&&(n.campaignContent=r),o&&(n.campaignKeyword=o),n}function w(i){var r=(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).customDimensions;return Object.keys(r).reduce(function(e,n){var t=r[n],a=function(e,n,t,a,i){for(n=n.split?n.split("."):n,a=0;a<n.length;a++)e=e?e[n[a]]:i;return e===i?t:e}(i,n)||i[n];return"boolean"==typeof a&&(a=a.toString()),(a||0===a)&&(e[t]=a),e},{})}function k(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=1<arguments.length?arguments[1]:void 0,t=2<arguments.length?arguments[2]:void 0,a=w(e,n);return Object.keys(a).length?n.setCustomDimensionsToPage?(ga("".concat(t,"set"),a),{}):a:{}}function a(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(!h()){var a=c(t).instancePrefix;if(e&&ga("".concat(a,"set"),"userId",e),Object.keys(n).length){var i=w(n,t);ga("".concat(a,"set"),i)}}}var i=n,r=n,o=s,l=a;return e.default=i,e.init=r,e.identify=l,e.track=o,e.page=void 0,e.initialize=void 0,e}({}); |
@@ -80,2 +80,3 @@ 'use strict'; | ||
* @param {string} [pluginConfig.customScriptSrc] - Custom URL for google analytics script, if proxying calls | ||
* @param {object} [pluginConfig.cookieConfig] - Additional cookie properties for configuring the [ga cookie](https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings) | ||
* @return {*} | ||
@@ -126,10 +127,9 @@ * @example | ||
if (!loadedInstances[instanceName]) { | ||
var gaConfig = { | ||
var gaConfig = _objectSpread({ | ||
cookieDomain: config.domain || 'auto', | ||
siteSpeedSampleRate: config.siteSpeedSampleRate || 1, | ||
sampleRate: config.sampleRate || 100, | ||
allowLinker: true // useAmpClientId: config.useAmpClientId | ||
allowLinker: true | ||
}, config.cookieConfig); | ||
}; | ||
if (instanceName) { | ||
@@ -136,0 +136,0 @@ gaConfig.name = instanceName; |
@@ -76,2 +76,3 @@ function _defineProperty(obj, key, value) { | ||
* @param {string} [pluginConfig.customScriptSrc] - Custom URL for google analytics script, if proxying calls | ||
* @param {object} [pluginConfig.cookieConfig] - Additional cookie properties for configuring the [ga cookie](https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings) | ||
* @return {*} | ||
@@ -122,10 +123,9 @@ * @example | ||
if (!loadedInstances[instanceName]) { | ||
var gaConfig = { | ||
var gaConfig = _objectSpread({ | ||
cookieDomain: config.domain || 'auto', | ||
siteSpeedSampleRate: config.siteSpeedSampleRate || 1, | ||
sampleRate: config.sampleRate || 100, | ||
allowLinker: true // useAmpClientId: config.useAmpClientId | ||
allowLinker: true | ||
}, config.cookieConfig); | ||
}; | ||
if (instanceName) { | ||
@@ -132,0 +132,0 @@ gaConfig.name = instanceName; |
{ | ||
"name": "@analytics/google-analytics", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Google analytics plugin for 'analytics' module", | ||
@@ -60,3 +60,3 @@ "projectMeta": { | ||
}, | ||
"gitHead": "fbadf71867ffc97a3014cad8c07eb9e8ddac23de" | ||
"gitHead": "da3547bebe98b20e86fd4899f4437b29c5a22520" | ||
} |
@@ -35,2 +35,3 @@ <!-- | ||
- [Custom Proxy Endpoint](#custom-proxy-endpoint) | ||
- [Cookie Config](#cookie-config) | ||
@@ -131,2 +132,3 @@ </details> | ||
| `customScriptSrc` <br/>_optional_ - string| Custom URL for google analytics script, if proxying calls | | ||
| `cookieConfig` <br/>_optional_ - object| Additional cookie properties for configuring the [ga cookie](https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings) | | ||
@@ -517,2 +519,39 @@ ## Server-side usage | ||
If using a proxied endpoint, it is recommended to combine this technique to with the [do-not-track](http://localhost:8000/plugins/do-not-track/) plugin to ensure website visitors privacy. | ||
If using a proxied endpoint, it is recommended to combine this technique to with the [do-not-track](https://getanalytics.io/plugins/do-not-track/) plugin to ensure website visitors privacy. | ||
## Cookie Config | ||
Some situations require changing the [cookie properties](https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings) of the Google Analytics cookie itself. | ||
The GA Cookie fields that are available are: | ||
| Field Name | Value Type | Default value | Description | | ||
|:---------------------------|:-----------|:------------------|:---------------------| | ||
| `cookieName`| text| _ga | Name of the cookie used to store analytics data | | ||
| `cookieDomain`| text| The result of the following JavaScript expression: *document.location.hostname* | Specifies the domain used to store the analytics cookie. Setting this to 'none' sets the cookie without specifying a domain. | | ||
| `cookieExpires`| integer| *63072000* (two years, in seconds) | Specifies the cookie expiration, in seconds. | | ||
| `cookieUpdate`| boolean| true | When cookieUpdate is set to true (the default value), analytics.js will update cookies on each page load. This will update the cookie expiration to be set relative to the most recent visit to the site. | | ||
| `cookieFlags`| text | | Specifies additional flags to append to the cookie. Flags must be separated by semicolons. | | ||
You can add these properties in the `cookieConfig` on the plugin config | ||
```js | ||
import Analytics from 'analytics' | ||
import googleAnalytics from '@analytics/google-analytics' | ||
const analytics = Analytics({ | ||
app: 'awesome-app', | ||
plugins: [ | ||
googleAnalytics({ | ||
trackingId: 'UA-1234567', | ||
cookieConfig: { | ||
cookieName: 'gaCookie', | ||
cookieDomain: 'blog.example.co.uk', | ||
cookieExpires: 60 * 60 * 24 * 28, // Time in seconds. | ||
cookieUpdate: 'false', | ||
cookieFlags: 'SameSite=None; Secure', | ||
} | ||
}) | ||
] | ||
}) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82840
1384
555