mirror of
https://github.com/a2nt/webpack-bootstrap-ui-kit.git
synced 2024-10-22 11:05:45 +02:00
IMPROVEMENT: google analytics external links tracker
This commit is contained in:
parent
d973668e3a
commit
c6f84ebc5d
2
dist/js/app.js
vendored
2
dist/js/app.js
vendored
File diff suppressed because one or more lines are too long
2
dist/js/app.js.map
vendored
2
dist/js/app.js.map
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@a2nt/ss-bootstrap-ui-webpack-boilerplate",
|
"name": "@a2nt/ss-bootstrap-ui-webpack-boilerplate",
|
||||||
"version": "1.7.1",
|
"version": "1.7.2",
|
||||||
"author": "Tony Air <tony@twma.pro>",
|
"author": "Tony Air <tony@twma.pro>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "This UI Kit allows you to build Bootstrap 4 webapp with some extra UI features. It's easy to extend and easy to convert HTML templates to CMS templates.",
|
"description": "This UI Kit allows you to build Bootstrap 4 webapp with some extra UI features. It's easy to extend and easy to convert HTML templates to CMS templates.",
|
||||||
|
61
src/js/_components/drivers/_google.track.external.links.js
Normal file
61
src/js/_components/drivers/_google.track.external.links.js
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
function _gaLt(event) {
|
||||||
|
if (typeof ga !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var el = event.srcElement || event.target;
|
||||||
|
|
||||||
|
/* Loop up the DOM tree through parent elements if clicked element is not a link (eg: an image inside a link) */
|
||||||
|
while (
|
||||||
|
el &&
|
||||||
|
(typeof el.tagName == 'undefined' ||
|
||||||
|
el.tagName.toLowerCase() != 'a' ||
|
||||||
|
!el.href)
|
||||||
|
) {
|
||||||
|
el = el.parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (el && el.href) {
|
||||||
|
/* link */
|
||||||
|
var link = el.href;
|
||||||
|
if (link.indexOf(location.host) == -1 && !link.match(/^javascript:/i)) {
|
||||||
|
/* external link */
|
||||||
|
/* HitCallback function to either open link in either same or new window */
|
||||||
|
var hitBack = function(link, target) {
|
||||||
|
target ? window.open(link, target) : (window.location.href = link);
|
||||||
|
};
|
||||||
|
/* Is target set and not _(self|parent|top)? */
|
||||||
|
var target =
|
||||||
|
el.target && !el.target.match(/^_(self|parent|top)$/i)
|
||||||
|
? el.target
|
||||||
|
: false;
|
||||||
|
/* send event with callback */
|
||||||
|
ga(
|
||||||
|
'send',
|
||||||
|
'event',
|
||||||
|
'Outgoing Links',
|
||||||
|
link,
|
||||||
|
document.location.pathname + document.location.search,
|
||||||
|
{ hitCallback: hitBack(link, target) },
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Prevent standard click */
|
||||||
|
event.preventDefault ? event.preventDefault() : (event.returnValue = !1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Attach the event to all clicks in the document after page has loaded */
|
||||||
|
var w = window;
|
||||||
|
w.addEventListener
|
||||||
|
? w.addEventListener(
|
||||||
|
'load',
|
||||||
|
() => {
|
||||||
|
document.body.addEventListener('click', _gaLt, !1);
|
||||||
|
},
|
||||||
|
!1,
|
||||||
|
)
|
||||||
|
: w.attachEvent &&
|
||||||
|
w.attachEvent('onload', () => {
|
||||||
|
document.body.attachEvent('onclick', _gaLt);
|
||||||
|
});
|
@ -79,6 +79,9 @@ import '@a2nt/meta-lightbox/src/js/index';
|
|||||||
import './_main';
|
import './_main';
|
||||||
import './_layout';
|
import './_layout';
|
||||||
|
|
||||||
|
// Google Analytics
|
||||||
|
import './_components/drivers/_google.track.external.links';
|
||||||
|
|
||||||
function importAll(r) {
|
function importAll(r) {
|
||||||
return r.keys().map(r);
|
return r.keys().map(r);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user