Skip to main content

E.1 Firebase Analytics

Firebase Analytics integration enables brokers to track user behavior across SSO (OAuth) flows, providing valuable insights into user engagement, conversion funnels, and system performance. This section outlines the implementation requirements and best practices for Firebase Analytics integration.

Overview

Firebase Analytics support enables:

  • User journey tracking across SSO (OAuth) flows
  • Conversion funnel analysis
  • Real-time event monitoring
  • Custom event tracking for broker-specific metrics
  • Integration with broader analytics ecosystems

Prerequisites

Before implementing Firebase Analytics, ensure:

  • Firebase Project: Active Firebase project with Analytics enabled
  • Platform Support: Target platforms support Firebase integration
  • Event Planning: Defined events and tracking strategy
  • Privacy Compliance: Compliance with privacy regulations

Implementation Requirements

Platform Support Conditions

Firebase Analytics functionality is available when both conditions are true:

  1. Mobile Platform: User accesses SSO (OAuth) screens using cTrader Mobile
  2. Analytics Enabled: Firebase Analytics is enabled for the integration

To enable Firebase Analytics, contact Spotware's Service Assurance team.

Event Tracking Parameter

The eventName query parameter enables Firebase event tracking:

ParameterData TypeDescription
eventNamestringThe name of the event to be sent to Firebase

Event Tracking Implementation

URL Parameter Usage

Add the eventName parameter to URLs hosting SSO (OAuth) screens:

<!-- Basic event tracking -->
https://brokerCrmUrl.com/auth/login?eventName=login_screen_view

<!-- With additional parameters -->
https://brokerCrmUrl.com/inapp/deposit?eventName=deposit_initiated&token=abc123&lang=en

<!-- Multi-step flow tracking -->
https://brokerCrmUrl.com/auth/signup?eventName=signup_step_1&firstLogin=true

Event Flow Tracking

When users are redirected between URLs during SSO (OAuth) flows, events are automatically sent to Firebase:

  1. User Flow Initiation: User starts SSO (OAuth) flow
  2. Screen Transitions: User moves between different screens
  3. Action Completion: User completes specific actions
  4. Flow Completion: User completes entire flow

Event Types and Examples

Standard Events

  • Screen Views: Track when users view specific screens
  • User Actions: Track user interactions and actions
  • Conversions: Track conversion events and goals
  • Errors: Track error events and issues

Custom Events

  • Business Metrics: Track broker-specific business metrics
  • User Segments: Track events by user segments
  • Campaign Performance: Track campaign-related events
  • Feature Usage: Track feature-specific usage patterns

Event Structure

{flow}_{action}_{step}

Examples

User Creation Flow Events

// Screen views
user_creation_screen_view
user_creation_form_display
user_creation_success_screen

// User actions
user_creation_form_started
user_creation_form_completed
user_creation_account_created

// Conversions
user_creation_completed
user_creation_converted

Deposit Flow Events

// Screen views
deposit_screen_view
deposit_method_selection
deposit_confirmation_screen

// User actions
deposit_amount_entered
deposit_method_selected
deposit_confirmed

// Conversions
deposit_initiated
deposit_completed
deposit_successful

KYC Flow Events

// Screen views
kyc_screen_view
kyc_document_upload
kyc_verification_screen

// User actions
kyc_started
kyc_document_uploaded
kyc_submitted

// Conversions
kyc_completed
kyc_verified
kyc_approved

Implementation Examples

Login Screen Tracking

<!-- Login screen with event tracking -->
https://brokerCrmUrl.com/auth/login?eventName=login_screen_view&firstLogin=true&lang=en&source=Mobile

Multi-Step Registration Tracking

<!-- Step 1: Basic information -->
https://brokerCrmUrl.com/auth/signup?eventName=signup_step_1_personal&firstLogin=true

<!-- Step 2: Account details -->
https://brokerCrmUrl.com/auth/signup/account?eventName=signup_step_2_account

<!-- Step 3: Verification -->
https://brokerCrmUrl.com/auth/signup/verify?eventName=signup_step_3_verification

<!-- Step 4: Success -->
https://brokerCrmUrl.com/auth/success?eventName=signup_completed&token=abc123

Deposit Flow Tracking

<!-- Deposit initiation -->
https://brokerCrmUrl.com/inapp/deposit?eventName=deposit_initiated&token=abc123&account=67890

<!-- Payment method selection -->
https://brokerCrmUrl.com/inapp/deposit/method?eventName=deposit_method_selected&method=credit_card

<!-- Deposit confirmation -->
https://brokerCrmUrl.com/inapp/deposit/confirm?eventName=deposit_confirmed&amount=1000

<!-- Deposit success -->
https://brokerCrmUrl.com/inapp/deposit/success?eventName=deposit_completed&amount=1000&method=credit_card

Analytics Use Cases

Funnel Analysis

User Creation Funnel

// Track funnel stages
1. login_screen_view (100%)
2. signup_form_started (85%)
3. signup_form_completed (70%)
4. account_created (65%)
5. signup_completed (60%)

Deposit Funnel

// Track deposit conversion
1. deposit_initiated (100%)
2. deposit_method_selected (90%)
3. deposit_confirmed (80%)
4. deposit_completed (75%)

User Behavior Analysis

Engagement Metrics

  • Screen Time: Time spent on each screen
  • Drop-off Points: Where users abandon flows
  • Completion Rates: Percentage of users completing flows
  • Error Rates: Frequency of errors by screen

Conversion Metrics

  • Conversion Rates: By flow and user segment
  • Time to Conversion: Average time to complete actions
  • Revenue Impact: Revenue generated by tracked actions
  • User Value: Lifetime value by acquisition channel

Performance Monitoring

System Performance

  • Load Times: Screen loading performance
  • Error Rates: System error frequency
  • API Performance: API response times
  • User Experience: User satisfaction metrics

Business Intelligence

  • User Segments: Behavior by user segments
  • Campaign Performance: Campaign effectiveness
  • Feature Adoption: Feature usage patterns
  • Retention Analysis: User retention metrics

Best Practices

Event Design

  • Consistent Naming: Use consistent event naming conventions
  • Descriptive Names: Use clear, descriptive event names
  • Logical Grouping: Group related events logically
  • Version Control: Version event schemas for compatibility

Data Quality

  • Validation: Validate event data before sending
  • Error Handling: Handle tracking errors gracefully
  • Data Cleansing: Clean and process event data
  • Quality Monitoring: Monitor data quality continuously

Privacy Compliance

  • Data Minimization: Collect only necessary data
  • User Consent: Obtain user consent for tracking
  • Anonymization: Anonymize sensitive user data
  • Retention Policies: Implement appropriate data retention

Technical Implementation

URL Parameter Handling

JavaScript Implementation

function trackEvent(eventName, additionalParams = {}) {
const url = new URL(window.location);
url.searchParams.set('eventName', eventName);

// Add additional parameters
Object.keys(additionalParams).forEach(key => {
url.searchParams.set(key, additionalParams[key]);
});

// Update URL without page reload
window.history.pushState({}, '', url);

// Firebase will automatically track the event
}

Server-Side Implementation

// Express.js example
app.get('/auth/login', (req, res) => {
const eventName = req.query.eventName || 'login_screen_view';

// Log event for analytics
logAnalyticsEvent(eventName, {
userId: req.user?.id,
timestamp: new Date().toISOString(),
userAgent: req.get('User-Agent'),
ip: req.ip
});

// Render login page
res.render('login', { eventName });
});

Event Validation

Client-Side Validation

function validateEventName(eventName) {
const validPatterns = [
/^[a-z_]+$/, // Lowercase letters and underscores only
/^.{1,40}$/ // Maximum 40 characters
];

return validPatterns.every(pattern => pattern.test(eventName));
}

Server-Side Validation

function validateEvent(eventName, params) {
const errors = [];

if (!eventName || typeof eventName !== 'string') {
errors.push('Event name is required and must be a string');
}

if (eventName.length > 40) {
errors.push('Event name must be 40 characters or less');
}

if (!/^[a-z_]+$/.test(eventName)) {
errors.push('Event name must contain only lowercase letters and underscores');
}

return {
isValid: errors.length === 0,
errors: errors
};
}

Analytics Integration

Firebase Configuration

Basic Setup

// Firebase initialization
import { initializeApp } from 'firebase/app';
import { getAnalytics } from 'firebase/analytics';

const firebaseConfig = {
apiKey: "your-api-key",
authDomain: "your-project.firebaseapp.com",
projectId: "your-project-id",
measurementId: "your-measurement-id"
};

const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);

Custom Event Tracking

import { logEvent } from 'firebase/analytics';

function trackCustomEvent(eventName, parameters = {}) {
logEvent(analytics, eventName, {
timestamp: new Date().toISOString(),
...parameters
});
}

Data Export and Analysis

BigQuery Integration

-- Example query for user creation funnel
SELECT
event_name,
COUNT(DISTINCT user_pseudo_id) as unique_users,
COUNT(*) as total_events
FROM `your-project.analytics_events`
WHERE event_name LIKE 'signup_%'
GROUP BY event_name
ORDER BY event_name;

Data Studio Dashboard

  • Create custom dashboards for key metrics
  • Set up automated reports and alerts
  • Visualize funnel performance
  • Track conversion trends over time

Monitoring and Maintenance

Performance Monitoring

  • Event Volume: Monitor event volume and patterns
  • Data Quality: Track data quality metrics
  • System Performance: Monitor analytics system performance
  • Error Rates: Track analytics error rates

Maintenance Tasks

  • Schema Updates: Update event schemas as needed
  • Documentation: Maintain event documentation
  • Testing: Test analytics implementation regularly
  • Optimization: Optimize event tracking performance

Troubleshooting

Common Issues

Events Not Appearing

  • Check Firebase project configuration
  • Verify event naming conventions
  • Ensure proper Firebase initialization
  • Check network connectivity

Data Quality Issues

  • Validate event parameters
  • Check for duplicate events
  • Verify data types and formats
  • Monitor for missing data

Performance Issues

  • Optimize event payload size
  • Reduce event frequency if needed
  • Implement event batching
  • Monitor system resources

Debugging Tools

Firebase DebugView

// Enable debug mode
import { getAnalytics, logEvent } from 'firebase/analytics';

const analytics = getAnalytics();
logEvent(analytics, 'debug_event', { debug: true });

Console Logging

function debugEvent(eventName, params) {
console.log('Analytics Event:', eventName, params);
// Send to Firebase
trackEvent(eventName, params);
}

This Firebase Analytics integration provides comprehensive tracking capabilities for SSO (OAuth) flows, enabling brokers to gain valuable insights into user behavior and optimize their integration for maximum effectiveness.