custom_events_tracker 0.1.0 copy "custom_events_tracker: ^0.1.0" to clipboard
custom_events_tracker: ^0.1.0 copied to clipboard

A simple and extensible event tracking library for Flutter/Dart apps that logs events and sends them to your backend API.

Custom Events Tracker #

A simple and extensible event tracking library for Flutter/Dart apps that logs events and sends them to your backend API.

Easily log user interactions and system events, then send them to your backend API for analytics, monitoring, or auditing.
Perfect for integrating with tools like Metabase for powerful data visualization and insight.

Metabase

Features #

  • πŸ“± Track custom events with attributes from your mobile apps
  • πŸ”„ Offline support with automatic syncing when connectivity returns
  • πŸ”’ API key authentication for secure event reporting
  • πŸ“Š Structured event data format for consistent analytics
  • πŸ“± Platform detection (iOS/Android)
  • ⏱️ Proper timezone handling for accurate event timing

Installation #

Add this package to your Flutter project by adding the following to your pubspec.yaml:

dependencies:
  custom_events_tracker: <latest_release>

Then run:

flutter pub get

Usage #

Initialization #

Initialize the tracker service early in your app lifecycle (typically in main.dart):

import 'package:custom_events_tracker/custom_events_tracker.dart';
import 'package:flutter/material.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  await TrackerService().initialize(
    endpointUrl: 'https://your-api-endpoint.com/events',
    apiKey: 'your-api-key',
    env: 'development', // or 'production', 'staging', etc.
    userId: 123, // user's ID in your system
  );
  
  runApp(MyApp());
}

Tracking Events #

Track events anywhere in your app by calling the trackEvent method:

// Basic event with type only
TrackerService().trackEvent(
  type: 'button_click',
  attributes: {},
);

// Event with custom attributes
TrackerService().trackEvent(
  type: 'item_purchase',
  attributes: {
    'item_id': 'product_123',
    'price': 19.99,
    'currency': 'USD',
    'quantity': 2,
  },
);

Manual Flush #

You can manually flush pending events if needed:

await TrackerService().flushPendingEvents();

Event Structure #

Events are automatically structured with the following fields:

Field Description
id Unique UUID for each event
type The event type (specified by you)
attributes Custom attributes map (specified by you)
source Always "mobile"
platform "android" or "ios"
userId The user ID provided during initialization
userTime ISO 8601 timestamp with timezone information
userTimezone The user's timezone
env Environment from initialization

How It Works #

  1. Events are created with a unique ID and timestamped when tracked
  2. When online, events are immediately sent to your backend
  3. When offline, events are stored in a local Hive CE database
  4. When connectivity returns, queued events are automatically sent
  5. Failed sends are automatically queued for retry

Dependencies #

This package uses:

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

5
likes
0
points
113
downloads

Publisher

verified publisheristoria.app

Weekly Downloads

A simple and extensible event tracking library for Flutter/Dart apps that logs events and sends them to your backend API.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

connectivity_plus, flutter, hive_ce, hive_ce_flutter, http, intl, uuid

More

Packages that depend on custom_events_tracker