Event Tracking Overview
GoSquared event tracking captures custom user actions beyond standard page views. Track button clicks, form submissions, feature usage, conversions, and any business-critical interactions to understand user behavior and measure product engagement.
Basic Event Tracking
Simple Events
Track events with just a name:
_gs('event', 'Button Clicked');
_gs('event', 'Video Played');
_gs('event', 'Newsletter Signup');
Events with Properties
Add context with event properties:
_gs('event', 'Button Clicked', {
button_name: 'Sign Up',
button_location: 'homepage_hero',
button_color: 'blue'
});
_gs('event', 'Form Submitted', {
form_name: 'contact',
form_type: 'lead_generation',
source: 'homepage',
fields_completed: 5
});
_gs('event', 'Video Played', {
video_title: 'Product Demo',
video_duration: 120,
video_id: 'vid_123',
autoplay: false
});
Inline Event Tracking
Attach events directly to HTML elements:
<button onclick="_gs('event', 'CTA Clicked', {location: 'header'})">
Get Started
</button>
<a href="/pricing" onclick="_gs('event', 'Pricing Page Viewed', {source: 'nav'})">
Pricing
</a>
Event Categories
User Engagement Events
Track how users interact with your product:
// Feature usage
_gs('event', 'Feature Used', {
feature_name: 'advanced_search',
user_plan: 'pro',
time_spent_seconds: 45
});
// Content interaction
_gs('event', 'Article Read', {
article_id: 'art_123',
article_title: 'Getting Started Guide',
read_percentage: 85,
time_on_page: 180
});
// Social sharing
_gs('event', 'Content Shared', {
platform: 'twitter',
content_type: 'blog_post',
content_id: 'post_456'
});
Conversion Events
Track key conversion points:
// Account creation
_gs('event', 'Account Created', {
signup_method: 'google_oauth',
referral_source: 'organic',
plan_selected: 'free'
});
// Trial started
_gs('event', 'Trial Started', {
trial_duration_days: 14,
plan: 'professional',
credit_card_required: false
});
// Subscription
_gs('event', 'Subscription Created', {
plan_name: 'enterprise',
billing_cycle: 'annual',
discount_applied: 'ANNUAL20'
});
E-commerce Events
Track purchase funnel:
// Product viewed
_gs('event', 'Product Viewed', {
product_id: 'prod_123',
product_name: 'Wireless Headphones',
product_category: 'Electronics',
price: 99.99,
currency: 'USD'
});
// Add to cart
_gs('event', 'Added to Cart', {
product_id: 'prod_123',
quantity: 1,
price: 99.99,
cart_total: 149.98
});
// Checkout initiated
_gs('event', 'Checkout Started', {
cart_value: 149.98,
item_count: 2,
coupon_code: 'SAVE10'
});
Transaction Tracking
Track revenue-generating events with the transaction method:
Basic Transaction
_gs('transaction', {
id: 'txn_123',
revenue: 99.99
});
Complete Transaction
_gs('transaction', {
id: 'order_abc123',
revenue: 149.99,
shipping: 9.99,
tax: 12.00,
currency: 'USD'
});
Transaction with Properties
_gs('transaction', {
id: 'order_' + Date.now(),
revenue: 299.99,
shipping: 0,
tax: 24.00,
currency: 'USD',
// Additional properties
payment_method: 'credit_card',
coupon_used: 'SUMMER25',
discount_amount: 75.00,
items_count: 3,
first_purchase: false
});
Subscription Revenue
// Monthly subscription
_gs('transaction', {
id: 'sub_' + subscriptionId,
revenue: 49.99,
currency: 'USD',
type: 'subscription',
plan: 'professional',
billing_cycle: 'monthly'
});
// Annual subscription
_gs('transaction', {
id: 'sub_annual_' + subscriptionId,
revenue: 499.99,
currency: 'USD',
type: 'subscription',
plan: 'professional',
billing_cycle: 'annual',
discount: 100.00
});
Goal Tracking
Goals allow you to measure conversions without code changes.
Setting Up Goals
- Navigate to Settings → Goals in GoSquared dashboard
- Click "Create Goal"
- Define goal conditions:
- Event-based: Triggered when specific event fires
- Page-based: Triggered when specific page visited
- Property-based: Triggered when user property matches condition
Goal Configuration Examples
Email Signup Goal:
- Type: Event
- Event name: "Newsletter Signup"
- Value: Count as conversion
Purchase Goal:
- Type: Event
- Event name: "Purchase Completed"
- Value: Track revenue from transaction
Onboarding Goal:
- Type: Property
- Property:
onboarding_completed - Condition: equals
true
Tracking Goal Completions
Goals are tracked automatically when conditions are met:
// This triggers "Newsletter Signup" goal
_gs('event', 'Newsletter Signup', {
list: 'product_updates',
source: 'blog'
});
// This triggers "Purchase Completed" goal
_gs('transaction', {
id: 'order_123',
revenue: 99.99
});
// This triggers "Onboarding Completed" goal
_gs('properties', {
onboarding_completed: true
});
Event Naming Conventions
Follow consistent naming for better analytics:
Recommended Patterns
// Use Title Case for event names
_gs('event', 'Button Clicked'); // Good
_gs('event', 'button_clicked'); // Avoid
// Be specific but concise
_gs('event', 'Checkout Completed'); // Good
_gs('event', 'User Completed The Checkout Process'); // Too verbose
// Use consistent verb tense (past tense)
_gs('event', 'Video Played'); // Good
_gs('event', 'Play Video'); // Avoid
// Group related events with prefixes
_gs('event', 'Form Submitted');
_gs('event', 'Form Abandoned');
_gs('event', 'Form Field Error');
Property Naming
_gs('event', 'Product Purchased', {
// Use snake_case for properties
product_id: 'prod_123',
product_name: 'Premium Plan',
purchase_amount: 99.99,
// Include context
payment_method: 'stripe',
first_purchase: true,
// Add timestamps when relevant
cart_created_at: '2024-03-15T10:00:00Z'
});
Advanced Event Tracking
Conditional Event Tracking
function trackPurchase(order) {
_gs('transaction', {
id: order.id,
revenue: order.total
});
// Track high-value purchases differently
if (order.total > 500) {
_gs('event', 'High Value Purchase', {
order_value: order.total,
customer_tier: 'vip'
});
}
}
Time-Based Events
let startTime = Date.now();
document.getElementById('tutorial').addEventListener('complete', function() {
let duration = (Date.now() - startTime) / 1000;
_gs('event', 'Tutorial Completed', {
duration_seconds: duration,
steps_completed: 5
});
});
Error Tracking
window.addEventListener('error', function(e) {
_gs('event', 'JavaScript Error', {
error_message: e.message,
error_file: e.filename,
error_line: e.lineno,
page_url: window.location.href
});
});
Common Use Cases
Track Download
document.querySelectorAll('a[download]').forEach(link => {
link.addEventListener('click', function() {
_gs('event', 'File Downloaded', {
file_name: this.getAttribute('download'),
file_type: this.href.split('.').pop(),
download_source: window.location.pathname
});
});
});
Track Outbound Links
document.querySelectorAll('a[href^="http"]').forEach(link => {
if (!link.href.includes(window.location.hostname)) {
link.addEventListener('click', function() {
_gs('event', 'Outbound Link Clicked', {
destination_url: this.href,
link_text: this.textContent,
page_location: window.location.pathname
});
});
}
});
Track Scroll Depth
let milestones = [25, 50, 75, 100];
let tracked = new Set();
window.addEventListener('scroll', function() {
let scrollPercent = (window.scrollY / (document.body.scrollHeight - window.innerHeight)) * 100;
milestones.forEach(milestone => {
if (scrollPercent >= milestone && !tracked.has(milestone)) {
_gs('event', 'Page Scroll Depth', {
depth_percentage: milestone,
page_url: window.location.pathname
});
tracked.add(milestone);
}
});
});
Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| Events not appearing | Incorrect syntax | Check console for errors |
| Event names inconsistent | Typos in event names | Use constants for event names |
| Too many events | Over-tracking | Focus on business-critical events |
| Missing event properties | Properties not included | Always add relevant context |
| Transaction not tracking revenue | Missing id or revenue |
Include required fields |
Best Practices
- Consistent Naming: Use a defined naming convention across all events
- Include Context: Add properties that provide meaningful context
- Avoid Over-Tracking: Track events that matter for business decisions
- Test Events: Verify events appear in dashboard before deploying
- Document Events: Maintain an event taxonomy document
- Use Transactions: Always use
transactionfor revenue events - Set Up Goals: Configure goals for key conversion points
- Monitor Volume: Keep event volume manageable for analysis
- Version Properties: Include version numbers when tracking app events
- Privacy Compliance: Don't include PII in event properties