Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env node
'use strict'
require('dotenv').config()
import 'dotenv/config'

const config = require('./src/utils/config')
const customTracker = require('./src/utils/customTracker')
const { index, styles, scripts, tracker, build } = require('./src/ui/index')
import config from './src/utils/config.js'
import * as customTracker from './src/utils/customTracker.js'
import { index, styles, scripts, tracker, build } from './src/ui/index.js'

// Build files that are identical on every installation
if (config.isPreBuildMode === true) {
Expand Down
4 changes: 1 addition & 3 deletions functions/api.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'

/**
* A serverless function handler for the '/api' route, for use with Netlify.
*
* See:
* - https://docs.netlify.com/functions/overview/
*/
exports.handler = require('../src/serverless').handler
export { handler } from '../src/serverless.js'
17 changes: 1 addition & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"Tobias Reich <tobias@electerious.com>"
],
"description": "Self-hosted, Node.js based analytics tool for those who care about privacy",
"type": "module",
"main": "src/index.js",
"keywords": [
"server",
Expand Down
14 changes: 6 additions & 8 deletions src/aggregations/aggregateActions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'
import { INTERVALS_DAILY, INTERVALS_MONTHLY, INTERVALS_YEARLY } from '../constants/intervals.js'
import matchEvents from '../stages/matchEvents.js'

const intervals = require('../constants/intervals')
const matchEvents = require('../stages/matchEvents')

module.exports = (ids, average, interval, limit, dateDetails) => {
export default (ids, average, interval, limit, dateDetails) => {
const aggregation = [
matchEvents(ids),
{
Expand All @@ -17,9 +15,9 @@ module.exports = (ids, average, interval, limit, dateDetails) => {
aggregation[1].$group.count = average === true ? { $avg: '$value' } : { $sum: '$value' }

const dateExpression = { date: '$created', timezone: dateDetails.userTimeZone }
const matchDay = [ intervals.INTERVALS_DAILY ].includes(interval)
const matchMonth = [ intervals.INTERVALS_DAILY, intervals.INTERVALS_MONTHLY ].includes(interval)
const matchYear = [ intervals.INTERVALS_DAILY, intervals.INTERVALS_MONTHLY, intervals.INTERVALS_YEARLY ].includes(interval)
const matchDay = [ INTERVALS_DAILY ].includes(interval)
const matchMonth = [ INTERVALS_DAILY, INTERVALS_MONTHLY ].includes(interval)
const matchYear = [ INTERVALS_DAILY, INTERVALS_MONTHLY, INTERVALS_YEARLY ].includes(interval)

if (matchDay === true) aggregation[1].$group._id.day = { $dayOfMonth: dateExpression }
if (matchMonth === true) aggregation[1].$group._id.month = { $month: dateExpression }
Expand Down
8 changes: 3 additions & 5 deletions src/aggregations/aggregateActiveVisitors.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'
import { DURATIONS_LIMIT, DURATIONS_INTERVAL } from '../constants/durations.js'
import matchDomains from '../stages/matchDomains.js'

const { DURATIONS_LIMIT, DURATIONS_INTERVAL } = require('../constants/durations')
const matchDomains = require('../stages/matchDomains')

module.exports = (ids, dateDetails) => {
export default (ids, dateDetails) => {
const aggregation = [
matchDomains(ids),
{
Expand Down
20 changes: 9 additions & 11 deletions src/aggregations/aggregateDurations.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict'
import { INTERVALS_DAILY, INTERVALS_MONTHLY, INTERVALS_YEARLY } from '../constants/intervals.js'
import matchDomains from '../stages/matchDomains.js'
import projectDuration from '../stages/projectDuration.js'
import projectMinInterval from '../stages/projectMinInterval.js'
import matchLimit from '../stages/matchLimit.js'

const intervals = require('../constants/intervals')
const matchDomains = require('../stages/matchDomains')
const projectDuration = require('../stages/projectDuration')
const projectMinInterval = require('../stages/projectMinInterval')
const matchLimit = require('../stages/matchLimit')

module.exports = (ids, interval, limit, dateDetails) => {
export default (ids, interval, limit, dateDetails) => {
const aggregation = [
matchDomains(ids),
projectDuration(),
Expand All @@ -25,9 +23,9 @@ module.exports = (ids, interval, limit, dateDetails) => {
aggregation[0].$match.created = { $gte: dateDetails.includeFnByInterval(interval)(limit) }

const dateExpression = { date: '$created', timezone: dateDetails.userTimeZone }
const matchDay = [ intervals.INTERVALS_DAILY ].includes(interval)
const matchMonth = [ intervals.INTERVALS_DAILY, intervals.INTERVALS_MONTHLY ].includes(interval)
const matchYear = [ intervals.INTERVALS_DAILY, intervals.INTERVALS_MONTHLY, intervals.INTERVALS_YEARLY ].includes(interval)
const matchDay = [ INTERVALS_DAILY ].includes(interval)
const matchMonth = [ INTERVALS_DAILY, INTERVALS_MONTHLY ].includes(interval)
const matchYear = [ INTERVALS_DAILY, INTERVALS_MONTHLY, INTERVALS_YEARLY ].includes(interval)

if (matchDay === true) aggregation[4].$group._id.day = { $dayOfMonth: dateExpression }
if (matchMonth === true) aggregation[4].$group._id.month = { $month: dateExpression }
Expand Down
6 changes: 2 additions & 4 deletions src/aggregations/aggregateNewActions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'
import matchEvents from '../stages/matchEvents.js'

const matchEvents = require('../stages/matchEvents')

module.exports = (ids, limit) => {
export default (ids, limit) => {
const aggregation = [
matchEvents(ids),
{
Expand Down
6 changes: 2 additions & 4 deletions src/aggregations/aggregateNewRecords.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'
import matchDomains from '../stages/matchDomains.js'

const matchDomains = require('../stages/matchDomains')

module.exports = (ids, properties, limit, or) => {
export default (ids, properties, limit, or) => {
const aggregation = [
matchDomains(ids),
{
Expand Down
6 changes: 2 additions & 4 deletions src/aggregations/aggregateRecentActions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'
import matchEvents from '../stages/matchEvents.js'

const matchEvents = require('../stages/matchEvents')

module.exports = (ids, limit) => {
export default (ids, limit) => {
const aggregation = [
matchEvents(ids),
{
Expand Down
6 changes: 2 additions & 4 deletions src/aggregations/aggregateRecentRecords.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'
import matchDomains from '../stages/matchDomains.js'

const matchDomains = require('../stages/matchDomains')

module.exports = (ids, properties, limit, or) => {
export default (ids, properties, limit, or) => {
const aggregation = [
matchDomains(ids),
{
Expand Down
16 changes: 7 additions & 9 deletions src/aggregations/aggregateTopActions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'
import { RANGES_LAST_24_HOURS, RANGES_LAST_7_DAYS, RANGES_LAST_30_DAYS, RANGES_LAST_6_MONTHS } from '../constants/ranges.js'
import matchEvents from '../stages/matchEvents.js'

const ranges = require('../constants/ranges')
const matchEvents = require('../stages/matchEvents')

module.exports = (ids, average, range, limit, dateDetails) => {
export default (ids, average, range, limit, dateDetails) => {
const aggregation = [
matchEvents(ids),
{
Expand All @@ -26,19 +24,19 @@ module.exports = (ids, average, range, limit, dateDetails) => {
aggregation[0].$match.key = { $ne: null }
aggregation[1].$group.count = average === true ? { $avg: '$value' } : { $sum: '$value' }

if (range === ranges.RANGES_LAST_24_HOURS) {
if (range === RANGES_LAST_24_HOURS) {
aggregation[0].$match.created = { $gte: dateDetails.lastHours(24) }
}

if (range === ranges.RANGES_LAST_7_DAYS) {
if (range === RANGES_LAST_7_DAYS) {
aggregation[0].$match.created = { $gte: dateDetails.lastDays(7) }
}

if (range === ranges.RANGES_LAST_30_DAYS) {
if (range === RANGES_LAST_30_DAYS) {
aggregation[0].$match.created = { $gte: dateDetails.lastDays(30) }
}

if (range === ranges.RANGES_LAST_6_MONTHS) {
if (range === RANGES_LAST_6_MONTHS) {
aggregation[0].$match.created = { $gte: dateDetails.lastMonths(6) }
}

Expand Down
16 changes: 7 additions & 9 deletions src/aggregations/aggregateTopRecords.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'
import { RANGES_LAST_24_HOURS, RANGES_LAST_7_DAYS, RANGES_LAST_30_DAYS, RANGES_LAST_6_MONTHS } from '../constants/ranges.js'
import matchDomains from '../stages/matchDomains.js'

const ranges = require('../constants/ranges')
const matchDomains = require('../stages/matchDomains')

module.exports = (ids, properties, range, limit, dateDetails, or) => {
export default (ids, properties, range, limit, dateDetails, or) => {
const aggregation = [
matchDomains(ids),
{
Expand Down Expand Up @@ -36,19 +34,19 @@ module.exports = (ids, properties, range, limit, dateDetails, or) => {
aggregation[1].$group._id[property] = `$${ property }`
})

if (range === ranges.RANGES_LAST_24_HOURS) {
if (range === RANGES_LAST_24_HOURS) {
aggregation[0].$match.created = { $gte: dateDetails.lastHours(24) }
}

if (range === ranges.RANGES_LAST_7_DAYS) {
if (range === RANGES_LAST_7_DAYS) {
aggregation[0].$match.created = { $gte: dateDetails.lastDays(7) }
}

if (range === ranges.RANGES_LAST_30_DAYS) {
if (range === RANGES_LAST_30_DAYS) {
aggregation[0].$match.created = { $gte: dateDetails.lastDays(30) }
}

if (range === ranges.RANGES_LAST_6_MONTHS) {
if (range === RANGES_LAST_6_MONTHS) {
aggregation[0].$match.created = { $gte: dateDetails.lastMonths(6) }
}

Expand Down
14 changes: 6 additions & 8 deletions src/aggregations/aggregateViews.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'
import { INTERVALS_DAILY, INTERVALS_MONTHLY, INTERVALS_YEARLY } from '../constants/intervals.js'
import matchDomains from '../stages/matchDomains.js'

const intervals = require('../constants/intervals')
const matchDomains = require('../stages/matchDomains')

module.exports = (ids, unique, interval, limit, dateDetails) => {
export default (ids, unique, interval, limit, dateDetails) => {
const aggregation = [
matchDomains(ids),
{
Expand All @@ -24,9 +22,9 @@ module.exports = (ids, unique, interval, limit, dateDetails) => {
aggregation[0].$match.created = { $gte: dateDetails.includeFnByInterval(interval)(limit) }

const dateExpression = { date: '$created', timezone: dateDetails.userTimeZone }
const matchDay = [ intervals.INTERVALS_DAILY ].includes(interval)
const matchMonth = [ intervals.INTERVALS_DAILY, intervals.INTERVALS_MONTHLY ].includes(interval)
const matchYear = [ intervals.INTERVALS_DAILY, intervals.INTERVALS_MONTHLY, intervals.INTERVALS_YEARLY ].includes(interval)
const matchDay = [ INTERVALS_DAILY ].includes(interval)
const matchMonth = [ INTERVALS_DAILY, INTERVALS_MONTHLY ].includes(interval)
const matchYear = [ INTERVALS_DAILY, INTERVALS_MONTHLY, INTERVALS_YEARLY ].includes(interval)

if (matchDay === true) aggregation[1].$group._id.day = { $dayOfMonth: dateExpression }
if (matchMonth === true) aggregation[1].$group._id.month = { $month: dateExpression }
Expand Down
11 changes: 2 additions & 9 deletions src/constants/browsers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
'use strict'

const BROWSERS_TYPE_WITH_VERSION = 'WITH_VERSION'
const BROWSERS_TYPE_NO_VERSION = 'NO_VERSION'

module.exports = {
BROWSERS_TYPE_WITH_VERSION,
BROWSERS_TYPE_NO_VERSION,
}
export const BROWSERS_TYPE_WITH_VERSION = 'WITH_VERSION'
export const BROWSERS_TYPE_NO_VERSION = 'NO_VERSION'
Loading