@analytics/google-analytics
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -6,2 +6,13 @@ # Change Log | ||
## [1.0.4](https://github.com/DavidWells/analytics/compare/@analytics/google-analytics@1.0.3...@analytics/google-analytics@1.0.4) (2022-11-09) | ||
### Bug Fixes | ||
* fixes a sneaky bug that causes all ga4 events (gtag) to fire in debug mode ([1da35cb](https://github.com/DavidWells/analytics/commit/1da35cbef06d93605a4e82767f0e4c6a2ac9aca8)) | ||
## [1.0.3](https://github.com/DavidWells/analytics/compare/@analytics/google-analytics@1.0.2...@analytics/google-analytics@1.0.3) (2022-07-22) | ||
@@ -8,0 +19,0 @@ |
@@ -128,5 +128,11 @@ var analyticsGa = (function (exports) { | ||
var gtagConf = _objectSpread(_objectSpread(_objectSpread({}, defaultGtagConf), gtagConfig ? gtagConfig : {}), debug ? { | ||
debug_mode: true | ||
} : {}); | ||
var gtagConf = _objectSpread(_objectSpread({}, defaultGtagConf), gtagConfig ? gtagConfig : {}); // You must explicitly delete the debug_mode parameter or all sessions will fire in debug more. Setting it false is not enough. | ||
// https://support.google.com/analytics/answer/7201382?hl=en&ref_topic=9303319#zippy=%2Cgoogle-tag-websites:~:text=To%20disable%20debug%20mode%2C%20exclude%20the%20%27debug_mode%27%20parameter%3B%20setting%20the%20parameter%20to%20false%20doesn%27t%20disable%20debug%20mode. | ||
if (debug === true) { | ||
gtagConf.debug_mode = true; | ||
} else { | ||
delete gtagConf.debug_mode; | ||
} | ||
/* set custom dimensions from user traits */ | ||
@@ -163,3 +169,3 @@ | ||
}); // console.log('Set userid', payload.userId) | ||
} // TODO verify this | ||
} // TODO verify this | ||
// https://developers.google.com/analytics/devguides/collection/ga4/user-properties?technology=websites | ||
@@ -166,0 +172,0 @@ |
@@ -1,1 +0,1 @@ | ||
var analyticsGa=function(e){"use strict";function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function n(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?t(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var r={},o="https://www.googletagmanager.com/gtag/js",i={debug_mode:!1,send_page_view:!1,anonymize_ip:!1,allow_google_signals:!0,allow_ad_personalization_signals:!0,cookie_flags:""},c={gtagName:"gtag",dataLayerName:"ga4DataLayer",measurementIds:[],gtagConfig:i};function g(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=0,a=s(e.measurementIds),g=n(n({},c),e);return{name:"google-analytics",config:g,initialize:function(e){var t=e.config,c=e.instance,g=t.dataLayerName,s=t.customScriptSrc,d=t.gtagName,l=t.gtagConfig,p=t.debug;if(!u(s||o)){var w=g?"&l=".concat(g):"",f=document.createElement("script");f.async=!0,f.src=s||"".concat(o,"?id=").concat(a[0]).concat(w),document.body.appendChild(f)}window[g]||(window[g]=window[g]||[],window[d]=function(){window[g].push(arguments)},window[d]("js",new Date));var m=n(n(n({},i),l||{}),p?{debug_mode:!0}:{}),v=(c.user()||{}).traits||{};Object.keys(v).length&&window[d]("set","user_properties",v);for(var y=0;y<a.length;y++)r[a[y]]||(window[d]("config",a[y],m),r[a[y]]=!0)},identify:function(e){var t=e.payload,n=e.config.gtagName;window[n]&&a.length&&(t.userId&&window[n]("set",{user_id:t.userId}),Object.keys(t.traits).length&&window[n]("set","user_properties",t.traits))},page:function(e){var r=e.payload,o=e.config,i=e.instance,c=o.gtagName,g=o.gtagConfig;if(window[c]&&a.length){var s=r.properties,u=s.send_to,l=i.getState("context.campaign"),p={page_title:s.title,page_location:s.url,page_path:s.path||document.location.pathname,page_hash:s.hash,page_search:s.page_search,page_referrer:s.referrer},w=d(l),f=n(n(n({},u?{send_to:u}:{}),p),w);g&&g.send_page_view&&0===t||window[c]("event","page_view",f),t++}},track:function(e){var t=e.payload,r=e.config,o=e.instance,i=t.properties,c=t.event,g=o.getState("context.campaign"),s=r.gtagName;if(window[s]&&a.length){var u=d(g),l=n(n({},i),u);window[s]("event",c,l)}},loaded:function(){var e=g.dataLayerName,t=g.customScriptSrc,n=e&&window[e]&&Array.prototype.push===window[e].push;return u(t||o)&&n},methods:{addTag:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};window[g.gtagName]&&(window[g.gtagName]("config",e,t),a&&!a.includes(e)&&(a=a.concat(e)))},disable:function(e){for(var t=e?s(e):a,n=0;n<a.length;n++){var r=a[n];t.includes(r)&&(window["ga-disable-".concat(r)]=!0)}},enable:function(e){for(var t=e?s(e):a,n=0;n<a.length;n++){var r=a[n];t.includes(r)&&(window["ga-disable-".concat(r)]=!1)}}}}}function s(e){if(!e)throw new Error("No GA Measurement ID defined");if(Array.isArray(e))return e;if("string"==typeof e)return[e];throw new Error("GA Measurement ID must be string or array of strings")}function d(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={},n=e.id,a=e.name,r=e.source,o=e.medium,i=e.content,c=e.keyword;return n&&(t.campaignId=n),a&&(t.campaignName=a),r&&(t.campaignSource=r),o&&(t.campaignMedium=o),i&&(t.campaignContent=i),c&&(t.campaignKeyword=c),t}function u(e){var t=document.querySelectorAll("script[src]"),n=new RegExp("^".concat(e));return Boolean(Object.values(t).filter((function(e){return n.test(e.src)})).length)}var l=g,p=g;return e.default=l,e.init=p,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var analyticsGa=function(e){"use strict";function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function n(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?t(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var r={},o="https://www.googletagmanager.com/gtag/js",i={debug_mode:!1,send_page_view:!1,anonymize_ip:!1,allow_google_signals:!0,allow_ad_personalization_signals:!0,cookie_flags:""},c={gtagName:"gtag",dataLayerName:"ga4DataLayer",measurementIds:[],gtagConfig:i};function g(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=0,a=s(e.measurementIds),g=n(n({},c),e);return{name:"google-analytics",config:g,initialize:function(e){var t=e.config,c=e.instance,g=t.dataLayerName,s=t.customScriptSrc,d=t.gtagName,l=t.gtagConfig,p=t.debug;if(!u(s||o)){var w=g?"&l=".concat(g):"",f=document.createElement("script");f.async=!0,f.src=s||"".concat(o,"?id=").concat(a[0]).concat(w),document.body.appendChild(f)}window[g]||(window[g]=window[g]||[],window[d]=function(){window[g].push(arguments)},window[d]("js",new Date));var m=n(n({},i),l||{});!0===p?m.debug_mode=!0:delete m.debug_mode;var v=(c.user()||{}).traits||{};Object.keys(v).length&&window[d]("set","user_properties",v);for(var y=0;y<a.length;y++)r[a[y]]||(window[d]("config",a[y],m),r[a[y]]=!0)},identify:function(e){var t=e.payload,n=e.config.gtagName;window[n]&&a.length&&(t.userId&&window[n]("set",{user_id:t.userId}),Object.keys(t.traits).length&&window[n]("set","user_properties",t.traits))},page:function(e){var r=e.payload,o=e.config,i=e.instance,c=o.gtagName,g=o.gtagConfig;if(window[c]&&a.length){var s=r.properties,u=s.send_to,l=i.getState("context.campaign"),p={page_title:s.title,page_location:s.url,page_path:s.path||document.location.pathname,page_hash:s.hash,page_search:s.page_search,page_referrer:s.referrer},w=d(l),f=n(n(n({},u?{send_to:u}:{}),p),w);g&&g.send_page_view&&0===t||window[c]("event","page_view",f),t++}},track:function(e){var t=e.payload,r=e.config,o=e.instance,i=t.properties,c=t.event,g=o.getState("context.campaign"),s=r.gtagName;if(window[s]&&a.length){var u=d(g),l=n(n({},i),u);window[s]("event",c,l)}},loaded:function(){var e=g.dataLayerName,t=g.customScriptSrc,n=e&&window[e]&&Array.prototype.push===window[e].push;return u(t||o)&&n},methods:{addTag:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};window[g.gtagName]&&(window[g.gtagName]("config",e,t),a&&!a.includes(e)&&(a=a.concat(e)))},disable:function(e){for(var t=e?s(e):a,n=0;n<a.length;n++){var r=a[n];t.includes(r)&&(window["ga-disable-".concat(r)]=!0)}},enable:function(e){for(var t=e?s(e):a,n=0;n<a.length;n++){var r=a[n];t.includes(r)&&(window["ga-disable-".concat(r)]=!1)}}}}}function s(e){if(!e)throw new Error("No GA Measurement ID defined");if(Array.isArray(e))return e;if("string"==typeof e)return[e];throw new Error("GA Measurement ID must be string or array of strings")}function d(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={},n=e.id,a=e.name,r=e.source,o=e.medium,i=e.content,c=e.keyword;return n&&(t.campaignId=n),a&&(t.campaignName=a),r&&(t.campaignSource=r),o&&(t.campaignMedium=o),i&&(t.campaignContent=i),c&&(t.campaignKeyword=c),t}function u(e){var t=document.querySelectorAll("script[src]"),n=new RegExp("^".concat(e));return Boolean(Object.values(t).filter((function(e){return n.test(e.src)})).length)}var l=g,p=g;return e.default=l,e.init=p,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); |
@@ -129,5 +129,11 @@ 'use strict'; | ||
var gtagConf = _objectSpread(_objectSpread(_objectSpread({}, defaultGtagConf), gtagConfig ? gtagConfig : {}), debug ? { | ||
debug_mode: true | ||
} : {}); | ||
var gtagConf = _objectSpread(_objectSpread({}, defaultGtagConf), gtagConfig ? gtagConfig : {}); // You must explicitly delete the debug_mode parameter or all sessions will fire in debug more. Setting it false is not enough. | ||
// https://support.google.com/analytics/answer/7201382?hl=en&ref_topic=9303319#zippy=%2Cgoogle-tag-websites:~:text=To%20disable%20debug%20mode%2C%20exclude%20the%20%27debug_mode%27%20parameter%3B%20setting%20the%20parameter%20to%20false%20doesn%27t%20disable%20debug%20mode. | ||
if (debug === true) { | ||
gtagConf.debug_mode = true; | ||
} else { | ||
delete gtagConf.debug_mode; | ||
} | ||
/* set custom dimensions from user traits */ | ||
@@ -164,3 +170,3 @@ | ||
}); // console.log('Set userid', payload.userId) | ||
} // TODO verify this | ||
} // TODO verify this | ||
// https://developers.google.com/analytics/devguides/collection/ga4/user-properties?technology=websites | ||
@@ -167,0 +173,0 @@ |
@@ -125,5 +125,11 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
var gtagConf = _objectSpread(_objectSpread(_objectSpread({}, defaultGtagConf), gtagConfig ? gtagConfig : {}), debug ? { | ||
debug_mode: true | ||
} : {}); | ||
var gtagConf = _objectSpread(_objectSpread({}, defaultGtagConf), gtagConfig ? gtagConfig : {}); // You must explicitly delete the debug_mode parameter or all sessions will fire in debug more. Setting it false is not enough. | ||
// https://support.google.com/analytics/answer/7201382?hl=en&ref_topic=9303319#zippy=%2Cgoogle-tag-websites:~:text=To%20disable%20debug%20mode%2C%20exclude%20the%20%27debug_mode%27%20parameter%3B%20setting%20the%20parameter%20to%20false%20doesn%27t%20disable%20debug%20mode. | ||
if (debug === true) { | ||
gtagConf.debug_mode = true; | ||
} else { | ||
delete gtagConf.debug_mode; | ||
} | ||
/* set custom dimensions from user traits */ | ||
@@ -160,3 +166,3 @@ | ||
}); // console.log('Set userid', payload.userId) | ||
} // TODO verify this | ||
} // TODO verify this | ||
// https://developers.google.com/analytics/devguides/collection/ga4/user-properties?technology=websites | ||
@@ -163,0 +169,0 @@ |
{ | ||
"name": "@analytics/google-analytics", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Google analytics v4 plugin for 'analytics' module", | ||
@@ -56,3 +56,3 @@ "projectMeta": { | ||
}, | ||
"gitHead": "cce14c45bd1aeb666627e77945623f2e6603cb6d" | ||
"gitHead": "8151c6195808ab69f2fecd54a6878b961947bd71" | ||
} |
@@ -26,2 +26,3 @@ <!-- | ||
- [Legacy Google analytics v3](#legacy-google-analytics-v3) | ||
- [Using GA3 and GA4 together](#using-ga3-and-ga4-together) | ||
@@ -244,2 +245,29 @@ </details> | ||
For the older version of google analytics please see the `@analytics/google-analytics-v3` package at https://www.npmjs.com/package/@analytics/google-analytics-v3 | ||
For the older version of google analytics please see the [`@analytics/google-analytics-v3` package](https://www.npmjs.com/package/@analytics/google-analytics-v3) or the [GA3 plugin docs](https://getanalytics.io/plugins/google-analytics-v3/) | ||
## Using GA3 and GA4 together | ||
It is possible to use both GA3 and GA4 together shown below. Just remember GA3 will be deprecated starting in July of 2023 | ||
```js | ||
import Analytics from 'analytics' | ||
import googleAnalyticsPlugin from '@analytics/google-analytics' | ||
import googleAnalyticsV3Plugin from '@analytics/google-analytics-v3' | ||
/* Initialize analytics instance */ | ||
const analytics = Analytics({ | ||
app: 'my-app', | ||
plugins: [ | ||
/* Load Google Analytics v4 */ | ||
googleAnalyticsPlugin({ | ||
measurementIds: ['G-abc123'], | ||
}), | ||
/* Load Google Analytics v3 */ | ||
googleAnalyticsV3Plugin({ | ||
trackingId: 'UA-11111111-2', | ||
}), | ||
], | ||
}) | ||
analytics.page() | ||
``` |
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
67857
932
272