Title: Tracking Strategy Locale: en URL: https://sensorswave.cn/en/docs/data-integration/tracking-strategy/ Description: Choosing the right tracking strategy — client-side, server-side, or hybrid Choosing the right tracking strategy is key to successful data collection. This document helps you understand the strengths and trade-offs of client-side and server-side tracking, so you can make an informed decision based on your business needs. ## Why Does Tracking Strategy Matter? Your tracking strategy directly impacts: - **Data quality**: Different approaches can result in significant differences in data completeness - **Maintenance costs**: Cross-platform consistency and code maintenance complexity - **Business insights**: Whether you can accurately capture both user behaviors and business metrics - **Long-term scalability**: How easily your tracking scales as your business grows ## Two Tracking Approaches ### Client-Side Tracking Client-side tracking generates events on the user's device or browser and sends them to Sensors Wave. For example, when a user clicks the "Add to Cart" button, the JavaScript SDK can immediately record an `AddToCart` event. Client-side tracking is **essential for capturing user interactions** that only happen in the browser or app — such as clicks, page views, scrolling behavior, and navigation paths. These events cannot be observed from the server. **Advantages** - (Advantage) **Comprehensive UI interaction capture**: Records clicks, browsing, swipes, page dwell time, and other detailed user behaviors that are invisible to the server - (Advantage) **Good anonymous user support**: Naturally suited for tracking behaviors of users who are not logged in - (Advantage) **Rich device context**: Automatically captures device type, screen resolution, browser version, referral source, and other client-side environment information - (Advantage) **Excellent real-time capability**: Events are collected and sent the moment they occur, with very low latency **Limitations** - (Limitation) **Data loss risk**: Ad blockers and browser privacy settings may prevent data from being sent - (Limitation) **Cross-platform maintenance**: Web, iOS, Android, and other platforms require separate SDK integration and maintenance - (Limitation) **Difficult version management**: Tracking logic in older app versions is hard to update uniformly; bug fixes require waiting for users to upgrade **Best For** - Page views, button clicks, form interactions, navigation paths - Content engagement: article reading duration, video playback progress, scroll depth - User intent signals: product browsing, adding to cart, search queries, price comparison - Pre-login behavior: landing page interactions, onboarding flows **Code Example (JavaScript)** ```javascript // Record an event on the client when user clicks "Add to Cart" button document.getElementById('add-to-cart-btn').addEventListener('click', function() { sensorswave.trackEvent('AddToCart', { product_id: 'SKU-12345', product_name: 'Wireless Bluetooth Headphones', category: 'Electronics', price: 299.00, currency: 'CNY', from_page: 'product_detail' }); }); // Track page dwell time let pageStartTime = Date.now(); window.addEventListener('beforeunload', function() { const duration = Date.now() - pageStartTime; sensorswave.trackEvent('PageView', { page_url: window.location.href, duration_seconds: Math.floor(duration / 1000) }); }); ``` ### Server-Side Tracking Server-side tracking sends event data from your application server to Sensors Wave. For example, when a user completes a payment, your payment service can create a `Purchase` event and send it to Sensors Wave as part of its processing logic. Server-side tracking is **ideal for business-critical events** where data accuracy is paramount and the event naturally occurs in your backend logic. **Advantages** - (Advantage) **High data reliability**: Not affected by ad blockers or client-side environments — data is sent directly from your server with near-100% delivery rate - (Advantage) **Cross-platform consistency**: Implement once, and data format is unified across all platforms (Web, iOS, Android) - (Advantage) **Easy to maintain**: Centralized code management; bug fixes take effect immediately without waiting for client updates - (Advantage) **Better security**: Sensitive data (e.g., payment amounts, order details) is not exposed on the client **Limitations** - (Limitation) **Cannot capture UI interactions**: Unable to record clicks, swipes, page dwell time, and other front-end behaviors - (Limitation) **Complex anonymous user tracking**: Requires additional session management and Cookie/Token passing mechanisms - (Limitation) **Limited device context**: Does not have direct access to client-side environment information such as screen resolution or browser version **Best For** - Core transactions: order creation, payment success, refunds, subscription changes - Account lifecycle: user registration, login, profile updates, account deletion - Backend operations: API calls, data exports, permission changes - Financial operations: transfers, investments, billing **Code Example (Go)** ```go // Record an event on the server after user completes payment func handlePaymentSuccess(orderID string, userID string, amount float64) { user := sensorswave.User{ LoginID: userID, } client.TrackEvent(user, "Purchase", sensorswave.Properties{ "order_id": orderID, "total_amount": amount, "currency": "CNY", "payment_method": "alipay", }) } ``` ## Comparison Table | Dimension | Client-Side Tracking | Server-Side Tracking | |---------|-----------|-----------| | **Data Reliability** | (Limitation) May be blocked by ad blockers or privacy tools | (Advantage) Near-100% delivery, not affected by client environment | | **UI Interaction Capture** | (Advantage) Can record clicks, scrolling, navigation, and other behaviors | (Limitation) Cannot observe front-end interactions | | **Anonymous User Tracking** | (Advantage) Natively supports anonymous users | (Limitation) Requires additional session management | | **Device Context** | (Advantage) Captures device, browser, screen, and referral info | (Limitation) Limited access to client environment | | **Cross-Platform Consistency** | (Limitation) Requires separate implementation per platform | (Advantage) Implement once, unified across all platforms | | **Maintenance Cost** | (Limitation) Requires waiting for client updates | (Advantage) Centralized management, fixes take effect immediately | | **Data Security** | (Limitation) Data is visible on the client | (Advantage) Sensitive data stays on the server | | **Real-time Capability** | (Advantage) Events are sent immediately | Depends on when the server processes the event | ## How to Choose? ### Core Principle Most applications need **both** client-side and server-side tracking. The question is not "which one should I use?" but "which approach should I use for *each event*?" - **Events that can only be observed on the client** (clicks, page views, scrolling) → use client-side tracking - **Events that can only be observed on the server** (backend processing, cron jobs, third-party webhooks) → use server-side tracking - **Events that can be tracked from either side** (e.g., a form submission that triggers both a client event and a server API call) → **prefer server-side tracking** for higher data reliability ### Decision Flow For each event you want to track, follow these questions: 1. **Does this event involve a UI interaction?** (e.g., clicks, page views, scrolling, navigation) - Yes → **Use client-side tracking** 2. **Does this event happen purely on the server?** (e.g., backend processing, webhook, scheduled task) - Yes → **Use server-side tracking** 3. **Can this event be tracked from either side?** (e.g., form submission, purchase completion) - Yes → **Prefer server-side tracking** for better data reliability - If you also need to capture the surrounding UI context (e.g., which button was clicked, time spent on page before submitting), add a complementary client-side event ### Recommended Hybrid Approach Most applications adopt a **client-side + server-side hybrid architecture**, using each approach where it excels: | Event Type | Recommended Approach | Examples | |---------|---------|------| | **User Behavior Events** | Client-side tracking | Page views, button clicks, scrolling, navigation paths, search queries | | **Core Business Events** | Server-side tracking | User registration, order creation, payment success, refunds | | **System Events** | Server-side tracking | Error logs, performance monitoring, API calls | | **Events trackable from both sides** | Server-side preferred | Form submissions, feature activations, checkout completion | ## Implementation Recommendations ### 1. Start with Your Key Events Identify the events most critical to your business analysis, then choose the right approach for each: - **Client-side first**: If your primary goal is understanding user behavior and optimizing user experience, start with client-side tracking for key page views and interactions - **Server-side first**: If your primary goal is tracking business metrics (revenue, conversions, subscriptions), start with server-side tracking for core transaction events - **Both**: Most teams benefit from implementing a few high-value events on each side in parallel ### 2. Incremental Expansion Adopt an incremental approach: - **Phase 1**: Implement 5-10 key events using the approach best suited for each - **Phase 2**: Validate data quality and confirm event property accuracy - **Phase 3**: Gradually expand tracking coverage based on analysis needs ### 3. Data Quality Assurance Establish a complete data validation and monitoring system: - **Before implementation**: Define data quality standards and acceptance criteria - **During implementation**: Validate event formats and property completeness in the development environment - **After implementation**: Configure data anomaly monitoring and alerting mechanisms ### 4. Cross-Team Collaboration Clarify tracking responsibilities across different teams: - **Backend team**: Responsible for server-side tracking implementation and maintenance - **Frontend/Client team**: Responsible for client-side tracking implementation and maintenance - **Data team**: Responsible for data quality monitoring and requirements gathering - **Product team**: Responsible for defining the business events to track ## Important Notes - **Data privacy compliance**: Ensure your tracking strategy complies with data privacy regulations such as GDPR and CCPA, and obtain user consent before data collection - **Performance impact**: Excessive client-side tracking can affect application performance. Recommendations: - Use batch event sending instead of sending events individually - Avoid adding tracking code in the critical rendering path - Conduct performance testing and optimization on tracking code - **Version compatibility**: Client-side tracking must consider backward compatibility with older versions; establish version upgrade and deprecation strategies - **Data consistency**: Ensure event names and property definitions are consistent between server-side and client-side tracking ## Other Integration Methods In addition to using SDKs directly, you can also send data to Sensors Wave through the following methods: ### CDP / Tag Manager Integration If you already use a CDP (Customer Data Platform) or Tag Manager, you can route events to Sensors Wave through integration: - **Segment**: Integrate via Segment to manage multiple analytics tools from a single source - **Google Tag Manager**: Use GTM to manage and deploy tracking code - **Other CDPs**: RudderStack, mParticle, etc. ### Data Warehouse Integration If your data is already stored in a data warehouse, Sensors Wave can load data directly from the warehouse: - **Snowflake**: Import historical data and batch data from Snowflake - **BigQuery**: Sync data from Google BigQuery - **Other warehouses**: Redshift, ClickHouse, etc. > **Tip**: These integration methods are suitable for enterprises with existing data infrastructure, reducing duplicated development effort. ## Next Steps After completing your tracking strategy selection, it is recommended to proceed in the following order: 1. **[Integrate SDK](sdks/javascript.mdx)**: Integrate the appropriate Sensors Wave SDK based on your chosen tracking strategy 2. **[User Identification](user-identification.mdx)**: Establish user identity recognition and association mechanisms 3. **[Data Model Design](data-model.mdx)**: Build a standardized event and property data structure 4. **[Events and Properties](events-and-properties.mdx)**: Learn how to design and manage events and property information --- **Last updated**: April 14, 2026