Skip to content

Commit

Permalink
Added TRACKER_SCRIPT_URL env var.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Oct 29, 2024
1 parent 9758b55 commit 1225473
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
18 changes: 12 additions & 6 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require('dotenv').config();
const path = require('path');
const pkg = require('./package.json');

const TRACKER_SCRIPT = '/script.js';

const basePath = process.env.BASE_PATH;
const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT;
const cloudMode = process.env.CLOUD_MODE;
Expand All @@ -14,6 +16,7 @@ const forceSSL = process.env.FORCE_SSL;
const frameAncestors = process.env.ALLOWED_FRAME_URLS;
const privateMode = process.env.PRIVATE_MODE;
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME;
const trackerScriptURL = process.env.TRACKER_SCRIPT_URL;

const contentSecurityPolicy = [
`default-src 'self'`,
Expand Down Expand Up @@ -58,13 +61,20 @@ const headers = [
headers: defaultHeaders,
},
{
source: '/script.js',
source: TRACKER_SCRIPT,
headers: trackerHeaders,
},
];

const rewrites = [];

if (trackerScriptURL) {
rewrites.push({
source: TRACKER_SCRIPT,
destination: trackerScriptURL,
});
}

if (collectApiEndpoint) {
rewrites.push({
source: collectApiEndpoint,
Expand Down Expand Up @@ -100,7 +110,7 @@ if (trackerScriptName) {

rewrites.push({
source: normalizedSource,
destination: '/script.js',
destination: TRACKER_SCRIPT,
});

headers.push({
Expand Down Expand Up @@ -184,10 +194,6 @@ const config = {
async rewrites() {
return [
...rewrites,
{
source: '/script.js',
destination: 'https://tracker-script.umami.dev/',
},
{
source: '/telemetry.js',
destination: '/api/scripts/telemetry',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "umami",
"version": "2.13.2",
"version": "2.14.0",
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
"author": "Umami Software, Inc. <hello@umami.is>",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion rollup.tracker.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { terser } from 'rollup-plugin-terser';
export default {
input: 'src/tracker/index.js',
output: {
file: 'public/tracker.js',
file: 'public/script.js',
format: 'iife',
},
plugins: [
Expand Down

0 comments on commit 1225473

Please sign in to comment.