File size: 1,512 Bytes
bf3b56a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Loreify CTA blocks with per-Space, per-placement UTM attribution."""

import html as _html
from urllib.parse import urlencode

from .config import LOREIFY_TRIAL_URL, SpaceConfig, CTA


def cta_url(config: SpaceConfig, utm_content: str) -> str:
    params = {
        "utm_source": "huggingface",
        "utm_medium": "referral",
        "utm_campaign": config.utm_campaign,
        "utm_content": utm_content,
    }
    return f"{LOREIFY_TRIAL_URL}?{urlencode(params)}"


def cta_html(config: SpaceConfig, cta: CTA, subtext: str = "7-day free trial.") -> str:
    """One CTA block: copy, one dominant button, small subtext. Same-tab link."""
    if cta is None:
        return ""
    url = cta_url(config, cta.utm_content)
    onclick = (
        "if(window.posthog){posthog.capture('hf_loreify_cta_clicked',"
        f"{{placement:'{cta.utm_content}',"
        "generated_before_click:!!window.__lf_generated,"
        "device_type:(window.innerWidth<768?'mobile':'desktop')});}"
    )
    return (
        '<div class="lf-cta">'
        f"<p>{_html.escape(cta.copy)}</p>"
        f'<a class="lf-cta-btn" href="{url}" onclick="{_html.escape(onclick, quote=True)}">'
        f"{_html.escape(cta.button)}</a>"
        f'<p class="lf-cta-sub">{_html.escape(subtext)}</p>'
        "</div>"
    )


# Small script flipped to true after a successful tool run so CTA clicks can
# report generated_before_click. Wired by tools via gr.HTML update or js.
GENERATED_FLAG_JS = "() => { window.__lf_generated = true; }"