Telemetry blocks provide easy integration with popular analytics and tracking services. Add these to your app to monitor user behavior, track conversions, and gain insights.
Google Analytics
Integrate Google Analytics tracking into your Reflex application.
Usage
import reflex as rx
from reflex_ui.blocks.telemetry import (
get_google_analytics_trackers,
gtag_report_conversion,
)
def app():
return rx.fragment(
rx.head(
*get_google_analytics_trackers("G-XXXXXXXXXX"),
),
# Your app content
)
Functions
get_google_analytics_trackers(tracking_id)
Returns a list of script components for Google Analytics.
Your Google Analytics tracking ID (e.g., “G-XXXXXXXXXX”).
Returns: list[rx.Component] - Google Tag Manager scripts
gtag_report_conversion(conversion_id_and_label)
Generates a script to report conversions to Google Ads.
The conversion label from Google Ads (e.g., “AW-123456789/AbC-D_efG-h12_34-567”).
Returns: rx.Component - Conversion tracking script
Example with Conversion Tracking
import reflex as rx
from reflex_ui.blocks.telemetry import (
get_google_analytics_trackers,
gtag_report_conversion,
)
class ConversionState(rx.State):
def track_signup(self):
return rx.call_script("gtag_report_conversion()")
def app():
return rx.fragment(
rx.head(
*get_google_analytics_trackers("G-XXXXXXXXXX"),
gtag_report_conversion("AW-123456789/AbC-D_efG-h12_34-567"),
),
rx.button(
"Sign Up",
on_click=ConversionState.track_signup,
),
)
PostHog
Integrate PostHog product analytics, feature flags, and session recording.
Usage
import reflex as rx
from reflex_ui.blocks.telemetry import get_posthog_trackers
def app():
return rx.fragment(
rx.head(
get_posthog_trackers(
project_id="phc_yourprojectid",
api_host="https://us.i.posthog.com",
),
),
# Your app content
)
Functions
get_posthog_trackers(project_id, api_host)
Your PostHog project ID (e.g., “phc_yourprojectid”).
api_host
str
default:"https://us.i.posthog.com"
PostHog API host URL. Use US or EU instance based on your project.
Returns: rx.Component - PostHog initialization script
User Identification
The PostHog script includes session recording and cross-origin iframe recording enabled by default.
Koala
Track B2B website visitors and identify companies visiting your site.
Usage
import reflex as rx
from reflex_ui.blocks.telemetry import get_koala_trackers
def app():
return rx.fragment(
rx.head(
get_koala_trackers("pk_your_public_api_key"),
),
# Your app content
)
Functions
get_koala_trackers(public_api_key)
Your Koala public API key.
Returns: rx.Component - Koala tracking script
Clearbit
Enrich your analytics with company data using Clearbit.
Usage
import reflex as rx
from reflex_ui.blocks.telemetry import get_clearbit_trackers
def app():
return rx.fragment(
rx.head(
get_clearbit_trackers("pk_your_public_key"),
),
# Your app content
)
Functions
get_clearbit_trackers(public_key)
Your Clearbit public key.
Returns: rx.Component - Clearbit tracking script
RB2B (Reveal Bot to Bot)
Identify anonymous website visitors and reveal company information.
Usage
import reflex as rx
from reflex_ui.blocks.telemetry import get_rb2b_trackers
def app():
return rx.fragment(
rx.head(
*get_rb2b_trackers(),
),
# Your app content
)
Functions
get_rb2b_trackers()
Returns pre-configured RB2B tracking scripts. No parameters needed as the tracking IDs are hardcoded.
Returns: list[rx.Component] - RB2B tracking scripts
Unify
Track intent data and visitor identification.
Usage
import reflex as rx
from reflex_ui.blocks.telemetry import get_unify_trackers
def app():
return rx.fragment(
rx.head(
get_unify_trackers(),
),
# Your app content
)
Functions
get_unify_trackers()
Returns pre-configured Unify tracking script. No parameters needed.
Returns: rx.Component - Unify tracking script
Common Room
Track community engagement and identify website visitors.
Usage
import reflex as rx
from reflex_ui.blocks.telemetry import (
get_common_room_trackers,
identify_common_room_user,
)
class UserState(rx.State):
email: str = ""
name: str = ""
def identify_user(self):
return identify_common_room_user(
email=self.email,
name=self.name,
)
def app():
return rx.fragment(
rx.head(
get_common_room_trackers("your_site_id"),
),
# Your app content
)
Functions
get_common_room_trackers(site_id)
Your Common Room site ID (found in your tracking snippet).
Returns: rx.Component - Common Room tracking script
identify_common_room_user(email, name)
Identify a user after form submission or login.
User’s full name (optional).
Returns: rx.event.EventSpec - Event to identify the user
Example with User Identification
import reflex as rx
from reflex_ui.blocks.telemetry import (
get_common_room_trackers,
identify_common_room_user,
)
class FormState(rx.State):
async def handle_signup(self, form_data: dict):
email = form_data.get("email")
name = form_data.get("name")
# Process signup...
# Identify in Common Room
return identify_common_room_user(email=email, name=name)
def app():
return rx.fragment(
rx.head(
get_common_room_trackers("your_site_id"),
),
rx.form(
rx.input(name="email"),
rx.input(name="name"),
rx.button("Sign Up", type="submit"),
on_submit=FormState.handle_signup,
),
)
Multiple Telemetry Services
You can use multiple telemetry services together:
import reflex as rx
from reflex_ui.blocks.telemetry import (
get_google_analytics_trackers,
get_posthog_trackers,
get_koala_trackers,
get_clearbit_trackers,
)
def app():
return rx.fragment(
rx.head(
# Google Analytics
*get_google_analytics_trackers("G-XXXXXXXXXX"),
# PostHog
get_posthog_trackers("phc_yourprojectid"),
# Koala for B2B tracking
get_koala_trackers("pk_your_api_key"),
# Clearbit for enrichment
get_clearbit_trackers("pk_your_key"),
),
# Your app content
)
Environment Variables
For security, store your tracking IDs in environment variables:
import os
import reflex as rx
from reflex_ui.blocks.telemetry import (
get_google_analytics_trackers,
get_posthog_trackers,
)
GA_ID = os.getenv("GOOGLE_ANALYTICS_ID")
POSTHOG_PROJECT_ID = os.getenv("POSTHOG_PROJECT_ID")
def app():
trackers = []
if GA_ID:
trackers.extend(get_google_analytics_trackers(GA_ID))
if POSTHOG_PROJECT_ID:
trackers.append(get_posthog_trackers(POSTHOG_PROJECT_ID))
return rx.fragment(
rx.head(*trackers),
# Your app content
)