Add the Insights Dart library
To send events to Algolia from your Flutter app, add the Insights Dart library to your project:- Add
algolia_insights: ^1.0.0
to yourpubspec.yaml
file. - Run
pub get
console command. - Add
import 'package:algolia_insights/algolia_insights.dart';
to your source files.
Add the Insights client
To add the Insights client, you’ll need your Algolia application ID, (search) API key, and auserToken
to identify your users.
You can find your application ID and API key in the Algolia dashboard.
Dart
Customizing the user token
You can set a custom user token by setting theuserToken
property on the Insights instance.
The user token is used to track events for a specific user.
If the user token isn’t specified, the system will automatically generate a token and store it on the device.
This auto-generated user token ensures that events are still associated with a unique user identifier, even if a custom token isn’t explicitly provided.
Dart
Send events from the HitsSearcher component
If you’re using multipleHits Searcher
widgets,
you must enable sending click events on each one separately.
This lets you choose which click events to track and which to ignore.
The HitsSearcher
component sends view events automatically.
It sets the clickAnalytics
parameter to get the queryID
.
With the queryID
parameter available, you can send click and conversion events:
Dart
HitsSearcher
class, set:
Dart
For the
positions
parameter of the clickedObjectIdsAfterSearch
method, the first object in the list of search results has a value of 1 (not 0), the second has a value of 2.Send events from the FacetList component
TheFacetList
component inherits the application ID, API key and index name parameters from the HitsSearcher
.
It also provides methods to track view, conversion, and click events for filters.
Dart
FacetList
class, set:
Dart
Send click, conversion, and view events from other sources
Use the following methods to send click, conversion, or view events:Dart