Skip to content

Logging and Analytics

We provide a wrapper around the firebase_analytics package to log events and errors in the app. This wrapper is called TechshoiAnalytics and is located in the core/infrastructure/analytics module. We also provide a logger class called TechshoiLogger to log messages in the app.

Logging

The TechshoiLogger class is a simple logger that logs messages to the console. It provides methods to log messages at different levels: debug, info, warning, and error. The logger is used throughout the app to log messages and errors.

Usage

To use the logger, import the core/infrastructure/logger/techshoi_logger.dart file and create an instance of the TechshoiLogger class. You can then use the logger to log messages at different levels.

dart
import 'package:techshoi_app/core/infrastructure/logger/techshoi_logger.dart';

TechshoiLogger.instance.i('This is a debug message');
TechshoiLogger.instance.e('This is an error message');

You can disable logging app-wide by setting the enableLogging property to false.

dart
TechshoiLogger.instance.enableLogging = false;

Analytics

The TechshoiAnalytics class is a wrapper around the firebase_analytics package. It provides methods to log events and errors in the app. The class is used to track user interactions and errors in the app.

Usage

To use the analytics wrapper, import the core/infrastructure/analytics/techshoi_analytics.dart file and create an instance of the TechshoiAnalytics class. You can then use the analytics wrapper to log events and errors in the app.

dart
import 'package:techshoi_app/core/infrastructure/analytics/techshoi_analytics.dart';

TechshoiAnalytics.instance.setUserId(id: 'user_id'); // Set the user ID. This will help you track user interactions.

TechshoiAnalytics.instance.logEvent('button_clicked', {'button_name': 'login'}); // Log an event with parameters.
TechshoiAnalytics.instance.logViewItem(
    value: 29.99, 
    currency: 'USD', 
    items: [
        TechshoiAnalyticsEventItem(
            itemId: 'item_id', 
            itemName: 'item_name', 
            itemCategory: 'item_category', 
            quantity: 1, 
            price: 29.99,
        ),
    ],
); // Log an item view event.

You can disable analytics app-wide by setting the enableLogging property to false.

dart
TechshoiAnalytics.enableLogging = false;