Spaces:
Sleeping
Sleeping
| """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; }" | |