@visual-framework/vf-analytics-google
Advanced tools
Comparing version 1.0.0-alpha.1 to 1.0.0-rc.1
@@ -1,13 +0,20 @@ | ||
# Changelog | ||
### 1.0.0-rc.1 | ||
## 1.0.0-alpha.1 | ||
* https://github.com/visual-framework/vf-core/issues/1059 | ||
* fixes typo `data-vf-google-analytics-region` from `data-vf-google-anlaytics-region` | ||
* 🚨 this may be breaking for some users of alpha.1 | ||
* extend scope to more than "a" tags | ||
* better detect areas where the event is fired | ||
* capture events that ignore "Click" events | ||
* captures more file types (txt,fasta) | ||
https://github.com/visual-framework/vf-core/issues/963 | ||
### 1.0.0-alpha.1 | ||
- Track the name of the link clicked | ||
- Track the region of the link clicked (global nav, masthead, hero, main content, footer, etc) | ||
- Track file type (PDF, DOC, etc) | ||
* https://github.com/visual-framework/vf-core/issues/963 | ||
* Track the name of the link clicked | ||
* Track the region of the link clicked (global nav, masthead, hero, main content, footer, etc) | ||
* Track file type (PDF, DOC, etc) | ||
## 1.0.0-alpha.0 | ||
### 1.0.0-alpha.0 | ||
- Initial release | ||
* Initial release |
{ | ||
"version": "1.0.0-alpha.1", | ||
"version": "1.0.0-rc.1", | ||
"name": "@visual-framework/vf-analytics-google", | ||
@@ -23,3 +23,3 @@ "description": "vf-analytics-google component", | ||
], | ||
"gitHead": "d7d571718e85d1f0c1ff3381ece0a029a8c3f494" | ||
"gitHead": "4390495a19d399f41d345eb38b884b338ce6f0e4" | ||
} |
@@ -38,3 +38,3 @@ # Google Analytics enhancements component | ||
### Verbos logging | ||
### Verbose logging | ||
@@ -41,0 +41,0 @@ `<body data-vf-google-analytics-verbose="true">` |
@@ -141,11 +141,17 @@ // vf-analytics-google | ||
document.body.onclick = function(e){ | ||
e = e || event; | ||
var from = findParent('a',e.target || e.srcElement); | ||
if (from){ | ||
document.body.addEventListener("mousedown", function (evt) { | ||
// send GA events if GA closest area is detected | ||
let closestContainer = getClosestGa(evt.target, '[data-vf-google-analytics-region]'); | ||
if (closestContainer) { | ||
analyticsTrackInteraction(evt.target); | ||
} else { | ||
var from = findParent('a',evt.target || evt.srcElement); | ||
if (from) { | ||
/* it's a link, actions here */ | ||
console.log('click',from); | ||
// console.log('clicked from findParent: ',from); | ||
analyticsTrackInteraction(from); | ||
} | ||
} | ||
} | ||
}, false ); | ||
//find first parent with tagName [tagname] | ||
@@ -163,2 +169,20 @@ function findParent(tagname,el){ | ||
/* | ||
* Find closest element that has GA attribute | ||
* @returns {el} the closest element with GA attribute | ||
*/ | ||
function getClosestGa(elem, selector) { | ||
// Element.matches() polyfill | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches | ||
if (!Element.prototype.matches) { | ||
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; | ||
} | ||
// Get the closest matching element | ||
for ( ; elem && elem !== document; elem = elem.parentNode ) { | ||
if ( elem.matches( selector ) ) return elem; | ||
} | ||
return null; | ||
}; | ||
/** | ||
@@ -198,2 +222,8 @@ * Utility method to get the last in an array | ||
} else { // then derive a value | ||
// Fix for when tags have undefined .innerText | ||
if (typeof actedOnItem.innerText === 'undefined') { | ||
actedOnItem.innerText = ''; | ||
} | ||
linkName = actedOnItem.innerText; | ||
@@ -214,6 +244,6 @@ console.log('linkName',linkName); | ||
// Track the region of the link clicked (global nav, masthead, hero, main content, footer, etc) | ||
//data-vf-google-anlaytics-region="main-content-area-OR-SOME-OTHER-NAME" | ||
let parentContainer = actedOnItem.closest("[data-vf-google-anlaytics-region]"); | ||
//data-vf-google-analytics-region="main-content-area-OR-SOME-OTHER-NAME" | ||
let parentContainer = actedOnItem.closest("[data-vf-google-analytics-region]"); | ||
if (parentContainer) { | ||
parentContainer = parentContainer.dataset.vfGoogleAnlayticsRegion; | ||
parentContainer = parentContainer.dataset.vfGoogleAnalyticsRegion; | ||
} else { | ||
@@ -232,3 +262,3 @@ parentContainer = 'No container specified'; | ||
// adapted from https://www.blastanalytics.com/blog/how-to-track-downloads-in-google-analytics | ||
var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3)$/i; | ||
var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3|txt|fasta)$/i; | ||
var baseHref = ''; | ||
@@ -251,3 +281,3 @@ var href = actedOnItem.href; | ||
let conditionalLoggingCheck = document.querySelector('body'); | ||
// debug: always turn on verbos analytics | ||
// debug: always turn on verbose analytics | ||
// conditionalLoggingCheck.setAttribute('data-vf-google-analytics-verbose', 'true'); | ||
@@ -254,0 +284,0 @@ if (conditionalLoggingCheck.dataset.vfGoogleAnalyticsVerbose) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
17931
325