From 369f63bc58133c4c8f83118ffa26a9c2198cd105 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Fri, 23 Jul 2021 15:17:32 +0300 Subject: [PATCH] Adds an option to rename the script file --- CHANGELOG.md | 1 + config/runtime.exs | 7 ++++++- lib/plausible_web/plugs/tracker.ex | 8 +++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eb5dd0f9..8a9cc0160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. - Menu (with auto-complete) to add new and edit existing filters directly plausible/analytics#1089 - Added `CLICKHOUSE_FLUSH_INTERVAL_MS` and `CLICKHOUSE_MAX_BUFFER_SIZE` configuration parameters plausible/analytics#1073 - Ability to invite users to sites with different roles plausible/analytics#1122 +- Option to configure a custom name for the script file ### Fixed - Fix weekly report time range plausible/analytics#951 diff --git a/config/runtime.exs b/config/runtime.exs index 48c08b58e..fca0206ac 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -136,6 +136,10 @@ is_selfhost = |> get_var_from_path_or_env("SELFHOST", "true") |> String.to_existing_atom() +custom_script_name = + config_dir + |> get_var_from_path_or_env("CUSTOM_SCRIPT_NAME", "script") + {site_limit, ""} = config_dir |> get_var_from_path_or_env("SITE_LIMIT", "50") @@ -171,7 +175,8 @@ config :plausible, admin_user_ids: admin_user_ids, site_limit: site_limit, site_limit_exempt: site_limit_exempt, - is_selfhost: is_selfhost + is_selfhost: is_selfhost, + custom_script_name: custom_script_name config :plausible, :selfhost, disable_authentication: disable_auth, diff --git a/lib/plausible_web/plugs/tracker.ex b/lib/plausible_web/plugs/tracker.ex index 8252f04c4..54f0f5471 100644 --- a/lib/plausible_web/plugs/tracker.ex +++ b/lib/plausible_web/plugs/tracker.ex @@ -2,7 +2,9 @@ defmodule PlausibleWeb.Tracker do import Plug.Conn use Agent + custom_script_name = Application.get_env(:plausible, :custom_script_name) base_variants = ["hash", "outbound-links", "exclusions", "compat"] + base_filenames = ["plausible", custom_script_name] # Generates Power Set of all variants variants = @@ -24,8 +26,8 @@ defmodule PlausibleWeb.Tracker do String.split(x, ".") |> Combination.permutate() |> Enum.map(fn p -> Enum.join(p, ".") end) - |> Enum.filter(fn permutation -> permutation != x end) - |> Enum.map(fn v -> "plausible.#{v}.js" end) + |> Enum.map(fn v -> Enum.map(base_filenames, fn filename -> "#{filename}.#{v}.js" end) end) + |> List.flatten() if Enum.count(variants) > 0 do {"plausible.#{x}.js", variants} @@ -33,7 +35,7 @@ defmodule PlausibleWeb.Tracker do end) |> Enum.reject(fn x -> x == nil end) |> Enum.into(%{}) - |> Map.put("plausible.js", ["analytics.js"]) + |> Map.put("plausible.js", ["analytics.js", "#{custom_script_name}.js"]) @templates files_available @aliases aliases_available