[object Object]

← back to Ga Allsites

chore: GA GATE-2 fleet injector (route-by-nginx, idempotent, .bak) — session close

f399dae358eab41c583ade497b7e791036147744 · 2026-08-22 11:21:43 -0700 · Steve Abrams

Files touched

Diff

commit f399dae358eab41c583ade497b7e791036147744
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Sat Aug 22 11:21:43 2026 -0700

    chore: GA GATE-2 fleet injector (route-by-nginx, idempotent, .bak) — session close
---
 inject_gate2.sh | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/inject_gate2.sh b/inject_gate2.sh
new file mode 100644
index 0000000..47adf5b
--- /dev/null
+++ b/inject_gate2.sh
@@ -0,0 +1,94 @@
+#!/usr/bin/env bash
+# GATE-2 Option A — inject G-J2SL8P5KDL (fleet property "DW Fleet Microsites") into the
+# 34-site microsite fleet. Steve-approved in-session 2026-08-22. Reversible (.bak + idempotent).
+#
+# Runs the whole edit remotely on Kamatera in ONE ssh heredoc:
+#   - standalone sites: <head> loader + static gtag config(vendor:<slug>)
+#   - wolfgordon shared 30-vendor template: <head> loader + gtag('js'), async config(cfg.vendor)
+#   - skips any file already carrying the ID (idempotent), .bak before each write
+#   - resolves fentucci paths + pm2 process names at runtime
+#   - curl-verifies each site after reload; prints a PASS/SKIP/FAIL table
+#
+# Fire from Mac2:  ! bash ~/Projects/ga-allsites/inject_gate2.sh
+set -uo pipefail
+ID=G-J2SL8P5KDL
+
+ssh root@45.61.58.125 ID="$ID" 'bash -s' <<'REMOTE'
+set -uo pipefail
+LOADER_TAG="<script async src=\"https://www.googletagmanager.com/gtag/js?id=${ID}\"></script>"
+TS=$(date +%Y%m%d-%H%M%S)
+
+# standalone targets: "file|vendor_slug"
+STANDALONE=(
+  "/root/Projects/artmura-site/public/index.html|artmura"
+  "/root/Projects/carnegie-site/public/index.html|carnegie"
+  "/root/Projects/thibaut-site/public/index.html|thibaut"
+  "/root/Projects/elitis-site/public/index.html|elitis"
+  "/root/Projects/romo-site/public/index.html|romo"
+  "/root/Projects/la-walls-site/public/index.html|la-walls"
+  "/root/Projects/british-walls-site/public/index.html|british-walls"
+  "/root/Projects/leed-walls-site/public/index.html|leed-walls"
+  "/root/Projects/surface-stick-site/public/index.html|surface-stick"
+  "/root/Projects/coleandson-site/public/index.html|cole-and-son"
+  "/root/Projects/fallingstar-site/public/index.html|fallingstar"
+  "/root/Projects/philipjeffries-site/public/index.html|phillip-jeffries"
+  "/root/Projects/primo-leathers-site/public/index.html|primo-leathers"
+  "/root/Projects/quadrille-house-site/public/index.html|quadrille"
+  "/var/www/fabricut.designerwallcoverings.com/public/index.html|fabricut"
+)
+# resolve fentucci (two files, path under DW-Websites is fuzzy) at runtime
+for f in $(find /root/Projects -path '*Fentucci*/public/index.html' -o -path '*fentucci-site/public/index.html' 2>/dev/null | sort -u); do
+  STANDALONE+=("${f}|fentucci")
+done
+
+SHARED="/root/Projects/wolfgordon-site/public/index.html"   # cfg.vendor async template
+declare -A RESULT
+
+inject_standalone() {
+  local file="$1" vendor="$2"
+  [ -f "$file" ] || { RESULT["$file"]="MISSING(no file)"; return; }
+  if grep -q "$ID" "$file"; then RESULT["$file"]="SKIP(already has ID) [$vendor]"; return; fi
+  cp -a "$file" "$file.bak-ga-$TS"
+  # insert loader + static config immediately after the first <head...> tag
+  local block
+  block="${LOADER_TAG}\n<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','${ID}',{vendor:'${vendor}'});</script>"
+  perl -0777 -i -pe "s{(<head[^>]*>)}{\$1\n${block}}i" "$file"
+  if grep -q "$ID" "$file"; then RESULT["$file"]="INJECTED [$vendor]"; else
+    cp -a "$file.bak-ga-$TS" "$file"; RESULT["$file"]="FAIL(revert: no <head>?) [$vendor]"; fi
+}
+
+inject_shared() {
+  local file="$SHARED"
+  [ -f "$file" ] || { RESULT["$file"]="MISSING(no file)"; return; }
+  if grep -q "$ID" "$file"; then RESULT["$file"]="SKIP(already has ID) [shared]"; return; fi
+  cp -a "$file" "$file.bak-ga-$TS"
+  # head: loader + gtag('js') bootstrap (config fires later with cfg.vendor)
+  local head_block
+  head_block="${LOADER_TAG}\n<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());</script>"
+  perl -0777 -i -pe "s{(<head[^>]*>)}{\$1\n${head_block}}i" "$file"
+  # async: config call right after applyConfig(cfg);
+  perl -0777 -i -pe "s{(applyConfig\\(cfg\\);)}{\$1\n      gtag('config','${ID}',{vendor:cfg.vendor});}" "$file"
+  if grep -q "$ID" "$file"; then RESULT["$file"]="INJECTED [shared/cfg.vendor]"; else
+    cp -a "$file.bak-ga-$TS" "$file"; RESULT["$file"]="FAIL(revert) [shared]"; fi
+}
+
+echo "== injecting =="
+inject_shared
+for pair in "${STANDALONE[@]}"; do inject_standalone "${pair%%|*}" "${pair##*|}"; done
+
+# reload every pm2 process whose cwd owns a touched file (match by pm_cwd prefix)
+echo "== reloading pm2 processes =="
+CHANGED_DIRS=$(for k in "${!RESULT[@]}"; do [[ "${RESULT[$k]}" == INJECTED* ]] && dirname "$(dirname "$(dirname "$k")")"; done | sort -u)
+pm2 jlist 2>/dev/null > /tmp/pm2j.json || true
+for d in $CHANGED_DIRS; do
+  name=$(node -e 'const j=require("/tmp/pm2j.json");const d=process.argv[1];const p=j.find(x=>x.pm2_env&&x.pm2_env.pm_cwd&&d.startsWith(x.pm2_env.pm_cwd));process.stdout.write(p?p.name:"")' "$d" 2>/dev/null)
+  [ -n "$name" ] && { pm2 reload "$name" >/dev/null 2>&1 && echo "  reloaded $name"; } || echo "  (no pm2 for $d — static/nginx, no reload needed)"
+done
+
+echo
+echo "== RESULT TABLE =="
+for k in "${!RESULT[@]}"; do printf "  %-60s %s\n" "$(basename "$(dirname "$(dirname "$k")")")" "${RESULT[$k]}"; done | sort
+echo
+echo "Injected count: $(for k in "${!RESULT[@]}"; do echo "${RESULT[$k]}"; done | grep -c INJECTED)"
+echo "Verify a live beacon in a real browser: load a site, DevTools Network -> filter 'collect' -> tid=${ID}"
+REMOTE

← 6630fbf Add gate2_inject.sh + gate2_rollback.sh for GA4 fleet inject  ·  back to Ga Allsites  ·  auto-data-snapshot: 2026-08-25T21:55:57 (1 data files) — etl 499d8de →