Skip to content

Commit

Permalink
feat(insights): expose internal client through eventTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
dhayab committed Aug 30, 2024
1 parent 0069853 commit bf6bb80
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions insights/lib/src/algolia_event_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class AlgoliaEventService implements EventService {
AlgoliaEventService.create(this._client)
: _log = Logger('Algolia/EventsService');

@override
InsightsClient get client => _client;

@override
void send(List<Event> events) => _client
.pushEvents(
Expand Down
4 changes: 4 additions & 0 deletions insights/lib/src/event_service.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:algolia_client_insights/algolia_client_insights.dart';

import 'event.dart';

/// Interface for the service that sends events
abstract class EventService {
InsightsClient get client;

/// Send a list of events
void send(List<Event> events);
}
4 changes: 4 additions & 0 deletions insights/lib/src/event_tracker.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:algolia_client_insights/algolia_client_insights.dart';

abstract class EventTracker {
/// Flag that blocks the sending of event packets when set to false
bool get isEnabled;

InsightsClient get client;

/// Send a filters click event
/// Optional custom [timestamp] can be provided.
void clickedFilters({
Expand Down
4 changes: 4 additions & 0 deletions insights/lib/src/hits_event_tracker.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:algolia_client_insights/algolia_client_insights.dart';

import '../algolia_insights.dart';

/// Wrapper for an EventTracker with associated indexName and queryID
Expand Down Expand Up @@ -92,4 +94,6 @@ class HitsEventTracker {
);
}
}

InsightsClient get client => tracker.client;
}
3 changes: 3 additions & 0 deletions insights/lib/src/insights.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:algolia_client_insights/algolia_client_insights.dart';
import 'package:collection/collection.dart';
import 'algolia_event_service.dart';
import 'event.dart';
Expand Down Expand Up @@ -66,6 +67,8 @@ class Insights implements EventTracker {

Insights.custom(this._service, this._userTokenStorage) : isEnabled = true;

InsightsClient get client => _service.client;

@override
void clickedFilters({
required String indexName,
Expand Down

0 comments on commit bf6bb80

Please sign in to comment.