Skip to content

Commit a71caec

Browse files
committed
Build share links from the live address and count visits on either host
GA only loaded on causalinferencelab.github.io, so moving the hub to causalinference.pseudo-lab.com would have stopped all measurement. GA now accepts both hosts, and copied links and share cards use the address the hub is served from. The forum calendar UID stays as is so existing calendar entries are not duplicated.
1 parent bb3bdd6 commit a71caec

5 files changed

Lines changed: 16 additions & 9 deletions

File tree

‎assets/js/ga.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
(Until November 2026 the hub loaded the web book's tag, G-BEBVKYH8HL, which sent every page to both the
77
web book's property and the hub's first stream, G-C5V0X2SGD3. That stream now only keeps the history.) */
88
const ID = "G-CS9K0E86LR";
9-
if (location.hostname === "causalinferencelab.github.io") {
9+
/* counted on the live hub only: its github.io address and the pseudo-lab.com address it can move to */
10+
if (["causalinferencelab.github.io", "causalinference.pseudo-lab.com"].includes(location.hostname)) {
1011
const s = document.createElement("script");
1112
s.async = true;
1213
s.src = `https://www.googletagmanager.com/gtag/js?id=${ID}`;

‎assets/js/helper.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
99
const norm = (s) => String(s || "").toLowerCase().replace(/[\s·\-_/()?!.,~'"]/g, "");
1010
const track = (n, p) => window.hubTrack && window.hubTrack(n, p);
11-
const SITE = "https://causalinferencelab.github.io/";
11+
const SITE = `${window.hubSite || "https://causalinferencelab.github.io"}/`;
1212
const BOOK = SITE + "Causal-Inference-with-Python/";
1313
const SAID = "cil-helper-said", QUIET = "cil-helper-quiet";
1414
const reduced = () => matchMedia("(prefers-reduced-motion: reduce)").matches;

‎assets/js/hub.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
2323
const fmt = (n) => Number(n).toLocaleString("ko-KR");
24+
/* the address printed on share cards: the live hub's host (track.js sets hubSite) */
25+
const siteHost = () => { try { return new URL(window.hubSite).host; } catch (e) { return "causalinferencelab.github.io"; } };
2426
const $ = (sel, root = document) => root.querySelector(sel);
2527
const dot = (d) => esc(String(d ?? "").replace(/-/g, "."));
2628
/* Data files come from pull requests: links must be http(s) or a site path, ids plain tokens,
@@ -647,7 +649,7 @@
647649
<p class="fc-tier">${esc(lv.tier || lv.name)}</p>
648650
${interest ? `<p class="fc-in"><span>관심</span>${esc(interest)}</p>` : ""}
649651
<label class="fc-name"><span>이름이나 닉네임 (선택, 저장하지 않음)</span><input type="text" maxlength="16" autocomplete="nickname" placeholder="예: 진수"></label>
650-
<p class="fc-foot">인과추론 Hub에서 3분 진단 · causalinferencelab.github.io</p>
652+
<p class="fc-foot">인과추론 Hub에서 3분 진단 · ${esc(siteHost())}</p>
651653
</div>
652654
<p class="lt-sub">같은 레벨이나 같은 관심 분야인 사람과 이야기를 시작해 보세요. 화면을 켜 둔 채 보여 주면 됩니다.</p></div>
653655
<div class="sh-foot"><button type="button" class="btn ghost" data-forum-back>결과로 돌아가기</button><button type="button" class="btn" data-goto-level="${lv.id}" data-test-go>${LV(lv.id)} 코스로 이동</button></div>`;
@@ -1628,7 +1630,7 @@
16281630
if (name) { c.fillStyle = "#fff"; c.font = font(700, 34); c.fillText(name, 80, H - 104); }
16291631
c.fillStyle = "rgba(255,255,255,.7)"; c.font = font(500, 24);
16301632
const d = new Date(), date = `${d.getFullYear()}.${pad2(d.getMonth() + 1)}.${pad2(d.getDate())}`;
1631-
c.fillText(`${date} · causalinferencelab.github.io`, 80, H - 60);
1633+
c.fillText(`${date} · ${siteHost()}`, 80, H - 60);
16321634
const mark = $(".banner-mark");
16331635
if (mark && mark.complete && mark.naturalWidth) c.drawImage(mark, W - 300, 70, 210, 210);
16341636
}
@@ -1672,7 +1674,7 @@
16721674
c.fillStyle = "#fff"; c.font = font(700, 24); c.fillText(m.name, x + 56, y + 9);
16731675
});
16741676
c.fillStyle = "rgba(255,255,255,.7)"; c.font = font(500, 22);
1675-
c.fillText(`causalinferencelab.github.io/builders/${info.slug || ""}`, 80, H - 56);
1677+
c.fillText(`${siteHost()}/builders/${info.slug || ""}`, 80, H - 56);
16761678
drawMedal(c, 930, 330, 150, t, p.cohorts.length);
16771679
}
16781680
async function openMedalCard(name) {

‎assets/js/library.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
function projectsHTML(list) {
181181
if (!list.length) return "";
182182
return `<section class="lib-pjs" aria-labelledby="lib-pjs-h"><h2 class="lib-pjs-h" id="lib-pjs-h">팀 프로젝트<span>저장소째 살펴보기</span></h2><ul>${list.map((r) => {
183-
const url = r.site ? (/^https?:/.test(r.site) ? r.site : `https://causalinferencelab.github.io/${String(r.site).replace(/^\//, "")}`) : `https://github.com/CausalInferenceLab/${r.repo}`;
183+
const url = r.site ? (/^https?:/.test(r.site) ? r.site : `${window.hubSite}/${String(r.site).replace(/^\//, "")}`) : `https://github.com/CausalInferenceLab/${r.repo}`;
184184
const lv = /^L[0-4]$/.test(r.level || "") ? `<b class="lib-lv lv-${r.level}">${r.level} ${LV_NAME[r.level]}</b>` : "";
185185
return `<li class="lib-pj" id="pj-${esc(r.repo)}" tabindex="-1"><a href="${esc(url)}" target="_blank" rel="noopener" data-event="library_click" data-event-params='${esc(JSON.stringify({ topic: "project", kind: "project", repo: r.repo, target: "project" }))}'>
186186
<span class="lib-pj-t">${esc(r.title)}<span class="lib-out" aria-hidden="true"> ↗</span></span><span class="lib-pj-s">${esc(r.summary || "")}</span><span class="lib-src">${lv}${r.site ? "사이트" : "GitHub"} · ${esc(r.repo)}</span></a></li>`;
@@ -232,7 +232,7 @@
232232
const terms = termsFor(t).slice(0, 3);
233233
return `${head}<article class="lib-topic s-${esc(t.shelf)}" id="${esc(t.id)}" tabindex="-1" aria-labelledby="t-${esc(t.id)}">
234234
<header><h3 id="t-${esc(t.id)}">${esc(t.name)}</h3><span class="lib-en" lang="en">${esc(t.en)}</span>
235-
<button type="button" class="lib-link" data-copy="${esc(`https://causalinferencelab.github.io/library.html#${t.id}`)}" data-share="library_topic" aria-label="${esc(t.name)} 링크 복사">링크 복사</button></header>
235+
<button type="button" class="lib-link" data-copy="${esc(`${window.hubSite}/library.html#${t.id}`)}" data-share="library_topic" aria-label="${esc(t.name)} 링크 복사">링크 복사</button></header>
236236
<p class="lib-about">${esc(t.about)}</p>
237237
${terms.length ? `<p class="lib-terms"><span>먼저 알아 둘 용어</span>${terms.map((x) => `<a href="#${esc(x.id)}" data-term="${esc(x.id)}">${esc(x.ko)}</a>`).join("")}</p>` : ""}
238238
${groupsHTML(v.items, t)}
@@ -294,7 +294,7 @@
294294
<section class="gl-col"><h4>팀 자료에서</h4>${team ? `<ul class="gl-team">${team}</ul>` : '<p class="gl-none">이 용어를 주로 다룬 팀 자료를 아직 찾지 못했습니다.</p>'}</section>
295295
</div>
296296
<p class="gl-acts">${tp ? `<span class="gl-tps"><span>자료실 주제</span>${tp}</span>` : ""}
297-
<span class="gl-btns"><button type="button" class="lib-link" data-copy="${esc(`https://causalinferencelab.github.io/library.html#${x.id}`)}" data-share="library_term" aria-label="${esc(x.ko)} 링크 복사">링크 복사</button>
297+
<span class="gl-btns"><button type="button" class="lib-link" data-copy="${esc(`${window.hubSite}/library.html#${x.id}`)}" data-share="library_term" aria-label="${esc(x.ko)} 링크 복사">링크 복사</button>
298298
<button type="button" class="lib-link" data-helper-ask="${esc(x.ko)} 알려 주세요">Pseudo에게 묻기</button>
299299
<a class="lib-link" href="${BOOK}glossary.html#${encodeURIComponent(x.id)}">웹북 용어집</a></span></p>
300300
</div>`;

‎assets/js/track.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
dictionary in the PM doc; keep them in snake_case and the params flat. */
44
(() => {
55
"use strict";
6-
const SITE = "https://causalinferencelab.github.io";
6+
/* the hub's own address for links people copy and share: wherever the live hub is served (github.io, or
7+
the pseudo-lab.com address it can move to); a local preview shares links to the live hub */
8+
const LIVE = ["causalinferencelab.github.io", "causalinference.pseudo-lab.com"];
9+
const SITE = LIVE.includes(location.hostname) ? location.origin : "https://causalinferencelab.github.io";
10+
window.hubSite = SITE;
711
window.hubTrack = (name, params = {}) => {
812
try {
913
if (typeof window.gtag === "function") window.gtag("event", name, params);

0 commit comments

Comments
 (0)