[object Object]

← back to Re Coverage Dashboard

wire own GA4 + FB Pixel (env-driven ids via server-injected window.__A, no-op until set); launchd env placeholders

ca8c4b95cb1b5f5b4190afe66a2b7dfa5e17873e · 2026-08-06 13:29:22 -0700 · Steve Abrams

Files touched

Diff

commit ca8c4b95cb1b5f5b4190afe66a2b7dfa5e17873e
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Thu Aug 6 13:29:22 2026 -0700

    wire own GA4 + FB Pixel (env-driven ids via server-injected window.__A, no-op until set); launchd env placeholders
---
 public/index.html | 16 ++++++++++++++++
 server.js         | 10 +++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/public/index.html b/public/index.html
index bacfd11..23fb380 100644
--- a/public/index.html
+++ b/public/index.html
@@ -126,6 +126,22 @@ async function refresh() {
 }
 refresh(); setInterval(refresh, 15000);
 </script>
+<!-- Own GA4 + FB Pixel (DW build standard). Ids come from server-injected window.__A
+     (GA4_ID / FB_PIXEL_ID env). Both no-op until their id is set — no tracking fires blank. -->
+<script>
+(function(){ var A=window.__A||{};
+  if (A.ga4) { var g=document.createElement('script'); g.async=true;
+    g.src='https://www.googletagmanager.com/gtag/js?id='+A.ga4; document.head.appendChild(g);
+    window.dataLayer=window.dataLayer||[]; function gtag(){dataLayer.push(arguments);}
+    window.gtag=gtag; gtag('js', new Date()); gtag('config', A.ga4); }
+  if (A.fb) { !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
+    n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;n.push=n;
+    n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
+    t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}
+    (window,document,'script','https://connect.facebook.net/en_US/fbevents.js');
+    fbq('init', A.fb); fbq('track', 'PageView'); }
+})();
+</script>
 <!-- DW-network ad slot (per the DW build standard): renders a "Sponsored" unit;
      every ad link is rel="nofollow sponsored noopener". Fail-open — no fill = nothing. -->
 <script src="https://ads.agentabrams.com/embed.js"
diff --git a/server.js b/server.js
index d749b79..b2ee958 100755
--- a/server.js
+++ b/server.js
@@ -113,7 +113,15 @@ const server = http.createServer((req, res) => {
   const file = req.url === '/' ? '/index.html' : req.url.split('?')[0];
   const fp = path.join(ROOT, 'public', file);
   if (fp.startsWith(path.join(ROOT, 'public')) && fs.existsSync(fp) && fs.statSync(fp).isFile()) {
-    res.setHeader('Content-Type', file.endsWith('.html') ? 'text/html' : 'text/plain');
+    if (file.endsWith('.html')) {
+      // Inject env-driven GA4 + FB-Pixel ids (per the DW build standard). Empty ids
+      // = the loaders no-op; set GA4_ID / FB_PIXEL_ID in the launchd plist env to arm.
+      let html = fs.readFileSync(fp, 'utf8');
+      const cfg = `<script>window.__A={ga4:${JSON.stringify(process.env.GA4_ID || '')},fb:${JSON.stringify(process.env.FB_PIXEL_ID || '')}};</script>`;
+      html = html.replace('</head>', cfg + '</head>');
+      res.setHeader('Content-Type', 'text/html'); res.end(html); return;
+    }
+    res.setHeader('Content-Type', 'text/plain');
     res.end(fs.readFileSync(fp)); return;
   }
   res.statusCode = 404; res.end('not found');

← 8480887 auto-data-snapshot: 2026-08-06T13:27:53 (1 data files) — lau  ·  back to Re Coverage Dashboard  ·  add inline SVG favicon (route + link) — silences the /favico d5ccf43 →