mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Renamed methods in tracker.
This commit is contained in:
parent
b19889638a
commit
9eca86a4fc
@ -64,7 +64,7 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const pageView = (url = currentUrl, referrer = currentRef, uuid = website) =>
|
const trackView = (url = currentUrl, referrer = currentRef, uuid = website) =>
|
||||||
collect(
|
collect(
|
||||||
'pageview',
|
'pageview',
|
||||||
{
|
{
|
||||||
@ -74,7 +74,7 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
uuid,
|
uuid,
|
||||||
);
|
);
|
||||||
|
|
||||||
const pageEvent = (event_value, event_type = 'custom', url = currentUrl, uuid = website) =>
|
const trackEvent = (event_value, event_type = 'custom', url = currentUrl, uuid = website) =>
|
||||||
collect(
|
collect(
|
||||||
'event',
|
'event',
|
||||||
{
|
{
|
||||||
@ -87,12 +87,12 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
|
|
||||||
/* Handle events */
|
/* Handle events */
|
||||||
|
|
||||||
const loadEvents = () => {
|
const addEvents = () => {
|
||||||
document.querySelectorAll("[class*='umami--']").forEach(element => {
|
document.querySelectorAll("[class*='umami--']").forEach(element => {
|
||||||
element.className.split(' ').forEach(className => {
|
element.className.split(' ').forEach(className => {
|
||||||
if (/^umami--([a-z]+)--([a-z0-9_]+[a-z0-9-_]+)$/.test(className)) {
|
if (/^umami--([a-z]+)--([a-z0-9_]+[a-z0-9-_]+)$/.test(className)) {
|
||||||
const [, type, value] = className.split('--');
|
const [, type, value] = className.split('--');
|
||||||
const listener = () => pageEvent(value, type);
|
const listener = () => trackEvent(value, type);
|
||||||
|
|
||||||
listeners.push([element, type, listener]);
|
listeners.push([element, type, listener]);
|
||||||
element.addEventListener(type, listener, true);
|
element.addEventListener(type, listener, true);
|
||||||
@ -123,17 +123,17 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
currentUrl = newUrl;
|
currentUrl = newUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
pageView(currentUrl, currentRef);
|
trackView(currentUrl, currentRef);
|
||||||
|
|
||||||
setTimeout(loadEvents, 300);
|
setTimeout(addEvents, 300);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Global */
|
/* Global */
|
||||||
|
|
||||||
if (!window.umami) {
|
if (!window.umami) {
|
||||||
const umami = event_value => pageEvent(event_value);
|
const umami = event_value => trackEvent(event_value);
|
||||||
umami.pageView = pageView;
|
umami.trackView = trackView;
|
||||||
umami.pageEvent = pageEvent;
|
umami.trackEvent = trackEvent;
|
||||||
|
|
||||||
window.umami = umami;
|
window.umami = umami;
|
||||||
}
|
}
|
||||||
@ -144,8 +144,8 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
history.pushState = hook(history, 'pushState', handlePush);
|
history.pushState = hook(history, 'pushState', handlePush);
|
||||||
history.replaceState = hook(history, 'replaceState', handlePush);
|
history.replaceState = hook(history, 'replaceState', handlePush);
|
||||||
|
|
||||||
pageView(currentUrl, currentRef);
|
trackView(currentUrl, currentRef);
|
||||||
|
|
||||||
loadEvents();
|
addEvents();
|
||||||
}
|
}
|
||||||
})(window);
|
})(window);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user