@justai/core 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.d.ts +6 -0
- package/src/index.js +72 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justai/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The framework-free heart of the persona shell — the load-bearing behaviour (auth capture, reveal, ready) as plain strings, so Astro and Next inject the SAME logic instead of each re-writing it.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
package/src/index.d.ts
CHANGED
|
@@ -9,3 +9,9 @@ export declare const REVEAL_CSS: string;
|
|
|
9
9
|
|
|
10
10
|
/** Self-reveal for a page with no kernel script (a 404, a sub-persona like feed). */
|
|
11
11
|
export declare const READY_JS: string;
|
|
12
|
+
|
|
13
|
+
/** Which GA4 measurement id a host reports into. The ecosystem's stream layout, declared once. */
|
|
14
|
+
export declare function measurementIdFor(host: string | null | undefined): string;
|
|
15
|
+
|
|
16
|
+
/** The whole analytics head block for a measurement id — non-production guard, consent defaults, config, deferred loader. */
|
|
17
|
+
export declare function analyticsJs(gaId: string): string;
|
package/src/index.js
CHANGED
|
@@ -56,3 +56,75 @@ export const REVEAL_CSS = `html.js body{opacity:0}html.js body.ready{opacity:1}`
|
|
|
56
56
|
export const READY_JS =
|
|
57
57
|
`var r=function(){document.body&&document.body.classList.add("ready")};` +
|
|
58
58
|
`if(document.readyState!=="loading")r();else addEventListener("DOMContentLoaded",r);setTimeout(r,400);`;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* queries: which measurement id does this host use · wrong GA4 stream · a persona reports into the
|
|
62
|
+
* wrong property · G-13L3BP6XCW vs G-K2J4FQTQ8L · how does feed pick its analytics tag
|
|
63
|
+
*
|
|
64
|
+
* THE ECOSYSTEM'S STREAM LAYOUT, declared once.
|
|
65
|
+
*
|
|
66
|
+
* One GA4 property, two web streams: `G-13L3BP6XCW` for app.zone and its personas, `G-K2J4FQTQ8L`
|
|
67
|
+
* for justai.pro and its own sub-domains. A page reports into whichever stream ITS CODE loads, so
|
|
68
|
+
* "app.zone versus justai.pro" is a fact about our code rather than a rule the platform enforces —
|
|
69
|
+
* put a persona on the wrong one and nothing errors, nothing is missing, the numbers simply land in
|
|
70
|
+
* the wrong column. That is why the mapping is a function here and not a constant copied per repo.
|
|
71
|
+
*
|
|
72
|
+
* A STATIC persona cannot call this — it has no host at build time — so @justai/cuts keeps its own
|
|
73
|
+
* default and `justai` passes the override. A SERVER-rendered surface (feed) knows the Host header
|
|
74
|
+
* and must use this. The two must agree; if a third stream ever appears, this is the one place it
|
|
75
|
+
* is added.
|
|
76
|
+
*/
|
|
77
|
+
export function measurementIdFor(host) {
|
|
78
|
+
const h = String(host || "").toLowerCase().split(":")[0];
|
|
79
|
+
return h === "justai.pro" || h.endsWith(".justai.pro") ? "G-K2J4FQTQ8L" : "G-13L3BP6XCW";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* queries: analytics inline script · gtag block · consent defaults · why is dev traffic in GA4 ·
|
|
84
|
+
* non-production guard · localhost 127.0.0.1 in analytics · how does a page start measuring
|
|
85
|
+
*
|
|
86
|
+
* The whole analytics head block, for any framework, given a measurement id.
|
|
87
|
+
*
|
|
88
|
+
* Everything load-bearing about it, in the order it matters:
|
|
89
|
+
*
|
|
90
|
+
* A NON-PRODUCTION PAGE MEASURES NOTHING. Found by reading the property through the analytics MCP:
|
|
91
|
+
* `127.0.0.1` and `localhost` were its TOP "persona" — 546 sessions in four days, and on one of them
|
|
92
|
+
* 127.0.0.1 alone outranked every real persona. Local dev and every headless verification sweep
|
|
93
|
+
* loading built HTML. The guard also covers the edge's `dev-` preview hosts: previews are rehearsals,
|
|
94
|
+
* not visits. Everything before 2026-07-24 in that property is inflated by this.
|
|
95
|
+
*
|
|
96
|
+
* `gtag` GOES ON `window`, never `function gtag`. A framework that scopes an injected variable wraps
|
|
97
|
+
* this in an IIFE, and a function declaration would then be trapped inside it — while the consent
|
|
98
|
+
* dialog's own script, elsewhere on the page, calls `gtag`. The failure is silent and specific: a
|
|
99
|
+
* European visitor clicks Allow, "gtag is not defined", the choice is never applied and the sheet
|
|
100
|
+
* never closes. The stub is also assigned BEFORE the guard returns, so a silenced host still has a
|
|
101
|
+
* callable `gtag` and that same script cannot throw there either.
|
|
102
|
+
*
|
|
103
|
+
* CONSENT DEFAULTS, twice: once globally granting only `analytics_storage`, once again for the EEA +
|
|
104
|
+
* UK + CH region list denying even that until the visitor consents. `ad_storage`, `ad_user_data` and
|
|
105
|
+
* `ad_personalization` are denied EVERYWHERE with no path to grant them — a decision, not an
|
|
106
|
+
* oversight, and the reason Google Ads reports zero conversions and a permanent "0% consent rate".
|
|
107
|
+
* The region list has a sibling: the timezone list in the consent dialog's script. Change one and the
|
|
108
|
+
* other must change, or a visitor is denied by region while never being offered the dialog.
|
|
109
|
+
*
|
|
110
|
+
* `page_title` IS PINNED at load. Only one persona mutates `document.title` today — time shows a live
|
|
111
|
+
* clock — and without this its analytics reports "13:32 · Amsterdam" as the page name. It costs every
|
|
112
|
+
* other persona nothing and removes a trap the next persona that animates its tab would walk into.
|
|
113
|
+
*
|
|
114
|
+
* The tag itself loads on idle after `load`: measurement must never compete with the kernel.
|
|
115
|
+
*/
|
|
116
|
+
export function analyticsJs(gaId) {
|
|
117
|
+
return `window.gtag=window.gtag||function(){(window.dataLayer=window.dataLayer||[]).push(arguments)};
|
|
118
|
+
var __h=location.hostname;
|
|
119
|
+
if(!(__h==="localhost"||__h==="127.0.0.1"||__h==="::1"||__h==="[::1]"||__h.indexOf("dev-")===0)){
|
|
120
|
+
var __g=${JSON.stringify(gaId)};
|
|
121
|
+
window.dataLayer=window.dataLayer||[];
|
|
122
|
+
window.gtag=window.gtag||function(){window.dataLayer.push(arguments)};
|
|
123
|
+
gtag("js",new Date());
|
|
124
|
+
gtag("consent","default",{ad_storage:"denied",ad_user_data:"denied",ad_personalization:"denied",analytics_storage:"granted"});
|
|
125
|
+
gtag("consent","default",{region:["AT","BE","BG","HR","CY","CZ","DK","EE","FI","FR","DE","GR","HU","IE","IT","LV","LT","LU","MT","NL","PL","PT","RO","SK","SI","ES","SE","IS","LI","NO","GB","CH"],ad_storage:"denied",ad_user_data:"denied",ad_personalization:"denied",analytics_storage:"denied"});
|
|
126
|
+
try{var __c=localStorage.getItem("consent");if(__c)gtag("consent","update",{analytics_storage:__c})}catch(e){}
|
|
127
|
+
gtag("config",__g,{cookie_expires:60*60*24*60,page_title:document.title,allow_google_signals:false,allow_ad_personalization_signals:false});
|
|
128
|
+
addEventListener("load",function(){(window.requestIdleCallback||function(f){setTimeout(f,1200)})(function(){var s=document.createElement("script");s.async=true;s.src="https://www.googletagmanager.com/gtag/js?id="+__g;document.head.appendChild(s)})});
|
|
129
|
+
}`;
|
|
130
|
+
}
|