diff --git a/probat/1db9df23-c7ca-4395-b929-65aa26949c93/0c07ddee-e9d0-405b-9119-145c0d19a527.tsx b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/0c07ddee-e9d0-405b-9119-145c0d19a527.tsx new file mode 100644 index 00000000..90291e97 --- /dev/null +++ b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/0c07ddee-e9d0-405b-9119-145c0d19a527.tsx @@ -0,0 +1,64 @@ +import React from 'react' +import './Hero.css' + +const Hero: React.FC = () => { + return ( +
+
+
+
+

+ Build Something + Amazing +

+

+ Create stunning websites and applications with our modern tools and + cutting-edge technology. Join thousands of developers who trust our platform. +

+
+ + +
+
+
+ 10K+ + Active Users +
+
+ 99.9% + Uptime +
+
+ 24/7 + Support +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default Hero \ No newline at end of file diff --git a/probat/1db9df23-c7ca-4395-b929-65aa26949c93/17a93140-b922-4fee-92cc-1a91362712c6.tsx b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/17a93140-b922-4fee-92cc-1a91362712c6.tsx new file mode 100644 index 00000000..98b1b027 --- /dev/null +++ b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/17a93140-b922-4fee-92cc-1a91362712c6.tsx @@ -0,0 +1,64 @@ +import React from 'react' +import './Hero.css' + +const Hero: React.FC = () => { + return ( +
+
+
+
+

+ Build Something + Amazing +

+

+ Create stunning websites and applications with our modern tools and + cutting-edge technology. Join thousands of developers who trust our platform. +

+
+ + +
+
+
+ 10K+ + Active Users +
+
+ 99.9% + Uptime +
+
+ 24/7 + Support +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default Hero \ No newline at end of file diff --git a/probat/1db9df23-c7ca-4395-b929-65aa26949c93/1e4a9571-c221-44da-a30f-5ff6b38abecd.tsx b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/1e4a9571-c221-44da-a30f-5ff6b38abecd.tsx new file mode 100644 index 00000000..db407617 --- /dev/null +++ b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/1e4a9571-c221-44da-a30f-5ff6b38abecd.tsx @@ -0,0 +1,70 @@ +import React from 'react' +import './Hero.css' + +const Hero: React.FC = () => { + return ( +
+
+
+
+

+ Build Something + Amazing +

+

+ Create stunning websites and applications with our modern tools and + cutting-edge technology. Join thousands of developers who trust our platform. +

+
+ + + Watch Demo + +
+
+
+ 10K+ + Active Users +
+
+ 99.9% + Uptime +
+
+ 24/7 + Support +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default Hero \ No newline at end of file diff --git a/probat/1db9df23-c7ca-4395-b929-65aa26949c93/2a340853-6b6b-47a0-abbc-9a527d1c6741.tsx b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/2a340853-6b6b-47a0-abbc-9a527d1c6741.tsx new file mode 100644 index 00000000..c6775311 --- /dev/null +++ b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/2a340853-6b6b-47a0-abbc-9a527d1c6741.tsx @@ -0,0 +1,64 @@ +import React from 'react' +import './Hero.css' + +const Hero: React.FC = () => { + return ( +
+
+
+
+

+ Build Something + Amazing +

+

+ Create stunning websites and applications with our modern tools and + cutting-edge technology. Join thousands of developers who trust our platform. +

+
+ + +
+
+
+ 10K+ + Active Users +
+
+ 99.9% + Uptime +
+
+ 24/7 + Support +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default Hero \ No newline at end of file diff --git a/probat/1db9df23-c7ca-4395-b929-65aa26949c93/51840ed1-40c6-4cbd-ba33-f7ec7b53f560.tsx b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/51840ed1-40c6-4cbd-ba33-f7ec7b53f560.tsx new file mode 100644 index 00000000..22434bb4 --- /dev/null +++ b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/51840ed1-40c6-4cbd-ba33-f7ec7b53f560.tsx @@ -0,0 +1,61 @@ +import React from 'react' +import './Hero.css' + +const Hero: React.FC = () => { + return ( +
+
+
+
+

+ Build Something + Amazing +

+

+ Create stunning websites and applications with our modern tools and + cutting-edge technology. Join thousands of developers who trust our platform. +

+
+ +
+
+
+ 10K+ + Active Users +
+
+ 99.9% + Uptime +
+
+ 24/7 + Support +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default Hero \ No newline at end of file diff --git a/probat/1db9df23-c7ca-4395-b929-65aa26949c93/8f21c2a2-5e86-4f16-89a3-72a22d59a8eb.tsx b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/8f21c2a2-5e86-4f16-89a3-72a22d59a8eb.tsx new file mode 100644 index 00000000..6a72c9c8 --- /dev/null +++ b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/8f21c2a2-5e86-4f16-89a3-72a22d59a8eb.tsx @@ -0,0 +1,64 @@ +import React from 'react' +import './Hero.css' + +const Hero: React.FC = () => { + return ( +
+
+
+
+

+ Build Something + Amazing +

+

+ Create stunning websites and applications with our modern tools and + cutting-edge technology. Join thousands of developers who trust our platform. +

+
+ + +
+
+
+ 10K+ + Active Users +
+
+ 99.9% + Uptime +
+
+ 24/7 + Support +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default Hero \ No newline at end of file diff --git a/probat/1db9df23-c7ca-4395-b929-65aa26949c93/984e4b19-c412-4aec-bb5b-3c214a8c23e9.tsx b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/984e4b19-c412-4aec-bb5b-3c214a8c23e9.tsx new file mode 100644 index 00000000..19c6b489 --- /dev/null +++ b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/984e4b19-c412-4aec-bb5b-3c214a8c23e9.tsx @@ -0,0 +1,64 @@ +import React from 'react' +import './Hero.css' + +const Hero: React.FC = () => { + return ( +
+
+
+
+

+ Build Something + Amazing +

+

+ Create stunning websites and applications with our modern tools and + cutting-edge technology. Join thousands of developers who trust our platform. +

+
+ + +
+
+
+ 99.9% + Uptime +
+
+ 10K+ + Active Users +
+
+ 24/7 + Support +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default Hero \ No newline at end of file diff --git a/probat/1db9df23-c7ca-4395-b929-65aa26949c93/c0fc681c-f985-481f-adc0-52bb28382da7.tsx b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/c0fc681c-f985-481f-adc0-52bb28382da7.tsx new file mode 100644 index 00000000..e477dfe8 --- /dev/null +++ b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/c0fc681c-f985-481f-adc0-52bb28382da7.tsx @@ -0,0 +1,64 @@ +import React from 'react' +import './Hero.css' + +const Hero: React.FC = () => { + return ( +
+
+
+
+

+ Build Something + Amazing +

+

+ Create stunning websites and applications with our modern tools and + cutting-edge technology. Join thousands of developers who trust our platform. +

+
+ + +
+
+
+ 10K+ + Active Users +
+
+ 99.9% + Uptime +
+
+ 24/7 + Support +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default Hero \ No newline at end of file diff --git a/probat/1db9df23-c7ca-4395-b929-65aa26949c93/e39bfa6b-caa7-4aa7-a1cc-debe8753743e.tsx b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/e39bfa6b-caa7-4aa7-a1cc-debe8753743e.tsx new file mode 100644 index 00000000..8e0f1675 --- /dev/null +++ b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/e39bfa6b-caa7-4aa7-a1cc-debe8753743e.tsx @@ -0,0 +1,70 @@ +import React from 'react' +import './Hero.css' + +const Hero: React.FC = () => { + return ( +
+
+
+
+

+ Build Something + Amazing +

+

+ Create stunning websites and applications with our modern tools and + cutting-edge technology. Join thousands of developers who trust our platform. +

+
+ + + Watch Demo + +
+
+
+ 10K+ + Active Users +
+
+ 99.9% + Uptime +
+
+ 24/7 + Support +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default Hero \ No newline at end of file diff --git a/probat/1db9df23-c7ca-4395-b929-65aa26949c93/f3e7d614-bb8d-4b34-b2a9-a7c0d4f00394.tsx b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/f3e7d614-bb8d-4b34-b2a9-a7c0d4f00394.tsx new file mode 100644 index 00000000..eb629de4 --- /dev/null +++ b/probat/1db9df23-c7ca-4395-b929-65aa26949c93/f3e7d614-bb8d-4b34-b2a9-a7c0d4f00394.tsx @@ -0,0 +1,66 @@ +import React from 'react' +import './Hero.css' + +const Hero: React.FC = () => { + return ( +
+
+
+
+

+ Build Something + Amazing +

+

+ Create stunning websites and applications with our modern tools and + cutting-edge technology. Join thousands of developers who trust our platform. +

+
+ + +
+
+
+ 10K+ + Active Users +
+
+
+ 99.9% + Uptime +
+
+
+ 24/7 + Support +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default Hero \ No newline at end of file diff --git a/probat/config.tsx b/probat/config.tsx new file mode 100644 index 00000000..1c69a1ee --- /dev/null +++ b/probat/config.tsx @@ -0,0 +1,4 @@ +// probat/config.tsx +export const PROBAT_COMPONENTS: Record = { + "src/components/Hero.tsx": { proposalId: "1db9df23-c7ca-4395-b929-65aa26949c93" } +}; diff --git a/probat/index.tsx b/probat/index.tsx new file mode 100644 index 00000000..c5493906 --- /dev/null +++ b/probat/index.tsx @@ -0,0 +1,4 @@ +// probat/index.tsx +export { withExperiment } from "./runtime"; +export { PROBAT_REGISTRIES } from "./registry"; +export { PROBAT_COMPONENTS } from "./config"; diff --git a/probat/registry.tsx b/probat/registry.tsx new file mode 100644 index 00000000..100c1dec --- /dev/null +++ b/probat/registry.tsx @@ -0,0 +1,26 @@ +// probat/registry.tsx + import type React from "react"; + import Exp_0_a from "./1db9df23-c7ca-4395-b929-65aa26949c93/0c07ddee-e9d0-405b-9119-145c0d19a527"; +import Exp_1_b from "./1db9df23-c7ca-4395-b929-65aa26949c93/c0fc681c-f985-481f-adc0-52bb28382da7"; +import Exp_2_c from "./1db9df23-c7ca-4395-b929-65aa26949c93/17a93140-b922-4fee-92cc-1a91362712c6"; +import Exp_3_d from "./1db9df23-c7ca-4395-b929-65aa26949c93/1e4a9571-c221-44da-a30f-5ff6b38abecd"; +import Exp_4_e from "./1db9df23-c7ca-4395-b929-65aa26949c93/2a340853-6b6b-47a0-abbc-9a527d1c6741"; +import Exp_5_f from "./1db9df23-c7ca-4395-b929-65aa26949c93/8f21c2a2-5e86-4f16-89a3-72a22d59a8eb"; +import Exp_6_g from "./1db9df23-c7ca-4395-b929-65aa26949c93/984e4b19-c412-4aec-bb5b-3c214a8c23e9"; +import Exp_7_h from "./1db9df23-c7ca-4395-b929-65aa26949c93/f3e7d614-bb8d-4b34-b2a9-a7c0d4f00394"; +import Exp_8_i from "./1db9df23-c7ca-4395-b929-65aa26949c93/e39bfa6b-caa7-4aa7-a1cc-debe8753743e"; +import Exp_9_j from "./1db9df23-c7ca-4395-b929-65aa26949c93/51840ed1-40c6-4cbd-ba33-f7ec7b53f560"; + export const PROBAT_REGISTRIES: Record>> = { + "src/components/Hero.tsx": { + "a": Exp_0_a, + "b": Exp_1_b, + "c": Exp_2_c, + "d": Exp_3_d, + "e": Exp_4_e, + "f": Exp_5_f, + "g": Exp_6_g, + "h": Exp_7_h, + "i": Exp_8_i, + "j": Exp_9_j, + }, + }; diff --git a/probat/runtime.tsx b/probat/runtime.tsx new file mode 100644 index 00000000..75893550 --- /dev/null +++ b/probat/runtime.tsx @@ -0,0 +1,150 @@ +// probat/runtime.tsx +import * as React from "react"; + +declare global { +interface Window { + __PROBAT_API?: string; +} +} + +const ENV_BASE: string = +(typeof import.meta !== "undefined" && (import.meta as any).env?.VITE_PROBAT_API) || +(typeof process !== "undefined" && (process as any).env?.NEXT_PUBLIC_PROBAT_API) || +(typeof window !== "undefined" && window.__PROBAT_API) || +"https://gushi.onrender.com"; + +const TTL_MS = 6 * 60 * 60 * 1000; // 6 hours +const KEY = (proposalId: string) => `probat_choice_v3:${proposalId}`; + +type RetrieveResponse = { +proposal_id: string; +experiment_id: string | null; +label: string | null; +}; + +type Choice = { +experiment_id: string; +label: string; +ts: number; +}; + +function safeGet(k: string): any | null { +try { + const raw = localStorage.getItem(k); + return raw ? JSON.parse(raw) : null; +} catch { + return null; +} +} +function safeSet(k: string, v: any) { +try { + localStorage.setItem(k, JSON.stringify(v)); +} catch {} +} +function now() { return Date.now(); } +function fresh(ts: number) { return now() - ts <= TTL_MS; } +function readChoice(proposalId: string): Choice | null { +const c = safeGet(KEY(proposalId)) as Choice | null; +return c && fresh(c.ts) ? c : null; +} +function writeChoice(proposalId: string, experiment_id: string, label: string) { +safeSet(KEY(proposalId), { experiment_id, label, ts: now() } as Choice); +} + +async function fetchDecision(baseUrl: string, proposalId: string): Promise<{ experiment_id: string; label: string }> { +const url = `${baseUrl.replace(/\/$/, "")}/retrieve_react_experiment/${encodeURIComponent(proposalId)}`; +const res = await fetch(url, { method: "POST", headers: { Accept: "application/json" } }); +if (!res.ok) throw new Error(`HTTP ${res.status}`); +const data = (await res.json()) as RetrieveResponse; + +const experiment_id = (data.experiment_id || `exp_${proposalId}`).toString(); +const label = data.label && data.label.trim() ? data.label : "control"; + +writeChoice(proposalId, experiment_id, label); +return { experiment_id, label }; +} + +async function sendClickMetric(baseUrl: string, proposalId: string, _experiment_id?: string, variant_label?: string) { +const url = `${baseUrl.replace(/\/$/, "")}/send_metrics/${encodeURIComponent(proposalId)}`; +const body = { + experiment_id: null, + variant_label: variant_label ?? "control", + metric_name: "click", + metric_value: 1, + metric_unit: "count", + source: "react", + dimensions: {}, + captured_at: new Date().toISOString(), +}; +try { + await fetch(url, { + method: "POST", + headers: { Accept: "application/json", "Content-Type": "application/json" }, + body: JSON.stringify(body), + }); +} catch {} +} + +type WithExperimentOpts = { +proposalId: string; +registry: Record>; +}; + +export function withExperiment

( +Control: React.ComponentType

, +opts: WithExperimentOpts +): React.ComponentType

void; probat?: { trackClick: () => void } }> { +const { proposalId, registry } = opts; + +function Wrapped(props: P) { + const [choice, setChoice] = React.useState<{ experiment_id: string; label: string } | null>(null); + + React.useEffect(() => { + let alive = true; + + const cached = readChoice(proposalId); + if (cached) { + setChoice({ experiment_id: cached.experiment_id, label: cached.label }); + } + + if (!cached) { + (async () => { + try { + const { experiment_id, label } = await fetchDecision(ENV_BASE, proposalId); + if (!alive) return; + setChoice({ experiment_id, label }); + } catch (e) { + if (!alive) return; + setChoice({ experiment_id: `exp_${proposalId}`, label: "control" }); + } + })(); + } + + return () => { alive = false; }; + }, [proposalId]); + + const trackClick = React.useCallback(() => { + const exp = choice?.experiment_id; + const lbl = choice?.label ?? "control"; + void sendClickMetric(ENV_BASE, proposalId, exp, lbl); + }, [proposalId, choice?.experiment_id, choice?.label]); + + const label = choice?.label ?? "control"; + const Variant = registry[label] || Control; + + const key = `${proposalId}:${label}`; + return ( +

+ {React.createElement(Variant, { + key, + ...(props as any), + onProbatClick: trackClick, + probat: { trackClick }, + })} +
+ ); +} + +(Wrapped as any).displayName = `withExperiment(${(Control as any).displayName || Control.name || "Component"})`; +return Wrapped as any; +} diff --git a/src/components/Hero.tsx b/src/components/Hero.tsx index 66d7f27c..8306d303 100644 --- a/src/components/Hero.tsx +++ b/src/components/Hero.tsx @@ -1,5 +1,9 @@ -import React from 'react' -import './Hero.css' +import React from "react"; +import { withExperiment } from "../../probat/runtime"; +import { PROBAT_COMPONENTS, PROBAT_REGISTRIES } from "../../probat/index"; +import './Hero.css'; + +const __PROBAT_KEY__ = "src/components/Hero.tsx"; const Hero: React.FC = () => { return ( @@ -61,4 +65,11 @@ const Hero: React.FC = () => { ) } -export default Hero +// Probat Generate Lines. +export default (() => { + const meta = PROBAT_COMPONENTS[__PROBAT_KEY__]; + const reg = PROBAT_REGISTRIES[__PROBAT_KEY__] as Record> | undefined; + return (meta?.proposalId && reg) + ? withExperiment(Hero as any, { proposalId: meta.proposalId, registry: reg }) + : Hero; +})();