Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Use rewrites for tracker script name, closes #972

Mike Cao460762bf3d11
diff --git a/Dockerfile b/Dockerfile
index e66ec5d5f..ee931167a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,9 +2,12 @@
FROM node:12.22-alpine AS build
ARG BASE_PATH
ARG DATABASE_TYPE
+ARG TRACKER_SCRIPT_NAME
+
ENV BASE_PATH=$BASE_PATH
-ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami" \
- DATABASE_TYPE=$DATABASE_TYPE
+ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami"
+ENV DATABASE_TYPE=$DATABASE_TYPE
+ENV TRACKER_SCRIPT_NAME=$TRACKER_SCRIPT_NAME
WORKDIR /build
RUN yarn config set --home enableTelemetry 0
diff --git a/next.config.js b/next.config.js
index dd8bfba05..8387e9ac3 100644
--- a/next.config.js
+++ b/next.config.js
@@ -1,14 +1,16 @@
require('dotenv').config();
const pkg = require('./package.json');
+const { BASE_PATH, FORCE_SSL, DISABLE_LOGIN, TRACKER_SCRIPT_NAME } = process.env;
+
module.exports = {
env: {
VERSION: pkg.version,
- FORCE_SSL: !!process.env.FORCE_SSL,
- DISABLE_LOGIN: !!process.env.DISABLE_LOGIN,
- TRACKER_SCRIPT_NAME: process.env.TRACKER_SCRIPT_NAME,
+ FORCE_SSL: Boolean(FORCE_SSL),
+ DISABLE_LOGIN: Boolean(DISABLE_LOGIN),
+ TRACKER_SCRIPT_NAME,
},
- basePath: process.env.BASE_PATH,
+ basePath: BASE_PATH,
eslint: {
ignoreDuringBuilds: true,
},
@@ -21,10 +23,15 @@ module.exports = {
return config;
},
+ async rewrites() {
+ return TRACKER_SCRIPT_NAME
+ ? [{ source: `/${TRACKER_SCRIPT_NAME}.js`, destination: '/umami.js' }]
+ : [];
+ },
async headers() {
return [
{
- source: '/umami.js',
+ source: `/${TRACKER_SCRIPT_NAME || 'umami'}.js`,
headers: [
{
key: 'Cache-Control',
diff --git a/rollup.tracker.config.js b/rollup.tracker.config.js
index 169f71fd3..5d2938ee2 100644
--- a/rollup.tracker.config.js
+++ b/rollup.tracker.config.js
@@ -3,12 +3,10 @@ import buble from '@rollup/plugin-buble';
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
-const scriptName = process.env.TRACKER_SCRIPT_NAME || 'umami';
-
export default {
input: 'tracker/index.js',
output: {
- file: `public/${scriptName}.js`,
+ file: 'public/umami.js',
format: 'iife',
},
plugins: [resolve(), buble({ objectAssign: true }), terser({ compress: { evaluate: false } })],