mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
add keepUnique method to mixpanel
This commit is contained in:
@@ -42,6 +42,17 @@ function _keep (name, properties) {
|
|||||||
localStorage.setItem('events', JSON.stringify(events))
|
localStorage.setItem('events', JSON.stringify(events))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _keepUnique (name, properties) {
|
||||||
|
let events = _fetch()
|
||||||
|
properties.time = new Date()
|
||||||
|
events = events.filter((event) => event.name !== name)
|
||||||
|
events.push({
|
||||||
|
name,
|
||||||
|
properties
|
||||||
|
})
|
||||||
|
localStorage.setItem('events', JSON.stringify(events))
|
||||||
|
}
|
||||||
|
|
||||||
function _flush () {
|
function _flush () {
|
||||||
let events = _fetch()
|
let events = _fetch()
|
||||||
let spliced = events.splice(0, 50)
|
let spliced = events.splice(0, 50)
|
||||||
@@ -79,10 +90,19 @@ function _flush () {
|
|||||||
setInterval(_flush, 1000 * 60 * 60)
|
setInterval(_flush, 1000 * 60 * 60)
|
||||||
|
|
||||||
function track (name, properties) {
|
function track (name, properties) {
|
||||||
properties = Object.assign({}, properties, {
|
switch (name) {
|
||||||
distinct_id: _getClientKey()
|
case 'MAIN_FOCUSED':
|
||||||
})
|
properties = Object.assign({}, properties, {
|
||||||
_keep(name, properties)
|
distinct_id: _getClientKey()
|
||||||
|
})
|
||||||
|
_keepUnique(name, properties)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
properties = Object.assign({}, properties, {
|
||||||
|
distinct_id: _getClientKey()
|
||||||
|
})
|
||||||
|
_keep(name, properties)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
Reference in New Issue
Block a user