how do I use amplitude's flutter package in a custom action?

417 Views Asked by At

I installed the following pub-dev package: https://pub.dev/packages/amplitude_flutter

Amplitude has a flutter SDK and a flutter package, allowing the app to send events to the Amplitude server.

I want to execute it within a custom action so that I can send events when the users perform specific actions.

Here is the code. IDE errors include:

Error: 'Amplitude' is imported from both 'package:amplitude_flutter/amplitude.dart' and 'package:amplitude_flutter/web/amplitude_js.dart

Error: Can't assign to the final variable 'analytics'.
analytics = Amplitude.getInstance(instanceName: "Assembly");
1

There are 1 best solutions below

0
On

For me, i used the following snippet:

analytics.logEvent('JUST CLICKED THE INDIGO BUTTON');

This is basically the event name, but we want to send a custom info or properties inside of it, so we need to use Identity like following:

final Identify identify1 = Identify()

Then we will attach any kind of information we want.

 final Identify identify1 = Identify()
            ..set('identify_test',
                'identify sent at ${DateTime.now().millisecondsSinceEpoch}')
            ..set('age_test', 30)
            ..set('nationality', 'Sudanese')
            ..set('current_city', 'Omdurman')
            ..add('identify_count', 1);
          analytics.identify(identify1);

          // Set group
          analytics.setGroup('orgId', 15);