Opensource Site Tracking Wiki
Self-hosted private analytics for real-time multi-site tracking.
Brought to you by:
autobotsolution
This guide explains how to set up and track conversion goals in OpenSite Analytics.
Goals allow you to track important conversions on your website, such as signups, purchases, or form submissions.
Track when users visit specific pages (e.g., thank you pages, confirmation pages).
Track when specific events occur (e.g., button clicks, form submissions).
curl -X POST http://localhost:8000/api/goals \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"site_id": 1,
"name": "Newsletter Signup",
"goal_type": "pageview",
"target_value": "/thank-you"
}'
Automatically tracked when user visits target page:
<!-- User visits /thank-you -->
<!-- Goal automatically recorded -->
Manually track events:
// Track goal completion
OpenSite('trackEvent', 'newsletter_signup', {
email: 'user@example.com'
})
@app.get("/api/goals/{site_id}/analytics")
async def get_goal_analytics(
site_id: int,
period: str = "7days",
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
goals = db.query(Goal).filter(Goal.site_id == site_id).all()
analytics = []
for goal in goals:
# Count goal completions
if goal.goal_type == "pageview":
count = db.query(PageView).filter(
PageView.url == goal.target_value,
PageView.created_at >= get_date_start(period)
).count()
else:
count = db.query(Event).filter(
Event.event_name == goal.target_value,
Event.created_at >= get_date_start(period)
).count()
analytics.append({
"goal_id": goal.id,
"goal_name": goal.name,
"completions": count
})
return analytics
Type: Event
Target: newsletter_signup
// On form submission
document.getElementById('newsletter-form').addEventListener('submit', (e) => {
OpenSite('trackEvent', 'newsletter_signup')
})
Type: Page View
Target: /purchase-success
// After successful purchase
window.location.href = '/purchase-success'
// Goal automatically tracked
Type: Event
Target: contact_form_submit
// On form submission
document.getElementById('contact-form').addEventListener('submit', (e) => {
OpenSite('trackEvent', 'contact_form_submit', {
form_id: 'contact-form'
})
})
Create multi-step funnels:
@app.post("/api/funnels")
async def create_funnel(
funnel: FunnelCreate,
current_user: User = Depends(get_current_user)
):
# Define funnel steps
steps = [
{"type": "pageview", "target": "/product"},
{"type": "pageview", "target": "/cart"},
{"type": "pageview", "target": "/checkout"},
{"type": "pageview", "target": "/success"}
]
funnel = Funnel(
name=funnel.name,
site_id=funnel.site_id,
steps=steps
)
db.add(funnel)
db.commit()
return funnel