mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
Updated .track method functionality.
This commit is contained in:
parent
80438bf84c
commit
71fcad26a5
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "umami",
|
"name": "umami",
|
||||||
"version": "2.0.2",
|
"version": "2.1.0",
|
||||||
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
|
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
|
||||||
"author": "Mike Cao <mike@mikecao.com>",
|
"author": "Mike Cao <mike@mikecao.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -169,7 +169,7 @@
|
|||||||
const send = payload => {
|
const send = payload => {
|
||||||
if (trackingDisabled()) return;
|
if (trackingDisabled()) return;
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json',
|
||||||
};
|
};
|
||||||
if (typeof cache !== 'undefined') {
|
if (typeof cache !== 'undefined') {
|
||||||
headers['x-umami-cache'] = cache;
|
headers['x-umami-cache'] = cache;
|
||||||
@ -177,17 +177,23 @@
|
|||||||
return fetch(endpoint, {
|
return fetch(endpoint, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ type: 'event', payload }),
|
body: JSON.stringify({ type: 'event', payload }),
|
||||||
headers: headers
|
headers,
|
||||||
})
|
})
|
||||||
.then(res => res.text())
|
.then(res => res.text())
|
||||||
.then(text => (cache = text));
|
.then(text => (cache = text));
|
||||||
};
|
};
|
||||||
|
|
||||||
const track = (name = {}, data = {}) => {
|
const track = (obj, data) => {
|
||||||
if (typeof name === 'string') {
|
if (typeof obj === 'string') {
|
||||||
return send({ ...getPayload(), ...data, name });
|
return send({
|
||||||
} else if (typeof name === 'object') {
|
...getPayload(),
|
||||||
return send({ ...getPayload(), ...name });
|
name: obj,
|
||||||
|
data: typeof data === 'object' ? data : undefined,
|
||||||
|
});
|
||||||
|
} else if (typeof obj === 'object') {
|
||||||
|
return send(obj);
|
||||||
|
} else if (typeof obj === 'function') {
|
||||||
|
return send(obj(getPayload()));
|
||||||
}
|
}
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user