@ons/design-system 70.0.2 → 70.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/analytics.js CHANGED
@@ -13,11 +13,20 @@ if (window.google_tag_manager !== undefined) {
13
13
  }
14
14
 
15
15
  export const trackElement = (el, type) => {
16
- return trackEvent(`ons_${type}`, {
17
- event_category: el.getAttribute('data-ga-category') || '',
18
- event_action: el.getAttribute('data-ga-action') || '',
19
- event_label: el.getAttribute('data-ga-label') || '',
20
- });
16
+ const attributes = el.attributes;
17
+ const eventData = {};
18
+ // Loop through all attributes of the element
19
+ for (let i = 0; i < attributes.length; i++) {
20
+ const attributeName = attributes[i].name;
21
+ // Check if the attribute starts with 'data-ga-'
22
+ if (attributeName.startsWith('data-ga-')) {
23
+ // Extract the key by removing 'data-ga-' prefix
24
+ const key = attributeName.replace('data-ga-', '').replace('-', '_');
25
+ // Use the attribute value as the value for the key
26
+ eventData[key] = el.getAttribute(attributeName);
27
+ }
28
+ }
29
+ return trackEvent(`ons_${type}`, eventData);
21
30
  };
22
31
 
23
32
  export default function initAnalytics() {
@@ -34,7 +43,9 @@ export default function initAnalytics() {
34
43
 
35
44
  document.body.addEventListener('click', ({ target }) => {
36
45
  if (target.getAttribute('data-ga') === 'click') {
37
- trackElement(target, target.getAttribute('data-ga'));
46
+ return trackElement(target, 'click');
47
+ } else if (target.parentElement.getAttribute('data-ga') === 'click') {
48
+ return trackElement(target.parentElement, 'click');
38
49
  }
39
50
  });
40
51
  [...document.querySelectorAll('[data-ga=error]')].map((element) => trackElement(element, 'error'));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ons/design-system",
3
3
  "description": "ONS Design System built CSS, JS, and Nunjucks templates",
4
- "version": "70.0.2",
4
+ "version": "70.0.4",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "author": {