From bf6bb80dde86b592cfb30f98529e10bcf097e564 Mon Sep 17 00:00:00 2001 From: Dhaya <154633+dhayab@users.noreply.github.com> Date: Fri, 30 Aug 2024 16:00:34 +0200 Subject: [PATCH] feat(insights): expose internal client through eventTracker --- insights/lib/src/algolia_event_service.dart | 3 +++ insights/lib/src/event_service.dart | 4 ++++ insights/lib/src/event_tracker.dart | 4 ++++ insights/lib/src/hits_event_tracker.dart | 4 ++++ insights/lib/src/insights.dart | 3 +++ 5 files changed, 18 insertions(+) diff --git a/insights/lib/src/algolia_event_service.dart b/insights/lib/src/algolia_event_service.dart index 5bc80a0..fa464d2 100644 --- a/insights/lib/src/algolia_event_service.dart +++ b/insights/lib/src/algolia_event_service.dart @@ -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 events) => _client .pushEvents( diff --git a/insights/lib/src/event_service.dart b/insights/lib/src/event_service.dart index 97aaaa1..23a9589 100644 --- a/insights/lib/src/event_service.dart +++ b/insights/lib/src/event_service.dart @@ -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 events); } diff --git a/insights/lib/src/event_tracker.dart b/insights/lib/src/event_tracker.dart index 86100d3..c3ce4c0 100644 --- a/insights/lib/src/event_tracker.dart +++ b/insights/lib/src/event_tracker.dart @@ -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({ diff --git a/insights/lib/src/hits_event_tracker.dart b/insights/lib/src/hits_event_tracker.dart index b2b3fc7..78fd2fc 100644 --- a/insights/lib/src/hits_event_tracker.dart +++ b/insights/lib/src/hits_event_tracker.dart @@ -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 @@ -92,4 +94,6 @@ class HitsEventTracker { ); } } + + InsightsClient get client => tracker.client; } diff --git a/insights/lib/src/insights.dart b/insights/lib/src/insights.dart index c62628b..2167299 100644 --- a/insights/lib/src/insights.dart +++ b/insights/lib/src/insights.dart @@ -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'; @@ -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,