项目作者: Countly

项目描述 :
Flutter SDK for Countly Product Analytics Platform
高级语言: Objective-C
项目地址: git://github.com/Countly/countly-sdk-flutter-bridge.git
创建时间: 2019-09-19T09:34:24Z
项目社区:https://github.com/Countly/countly-sdk-flutter-bridge

开源协议:MIT License

下载


Codacy Badge

Countly Flutter SDK

This repository contains the Countly Flutter SDK, which can be integrated into mobile Flutter applications. The Countly Flutter SDK is intended to be used with Countly Lite, Countly Flex, Countly Enterprise.

What is Countly?

Countly is a product analytics solution and innovation enabler that helps teams track product performance and customer journey and behavior across mobile, web,
and desktop applications. Ensuring privacy by design, Countly allows you to innovate and enhance your products to provide personalized and customized customer experiences, and meet key business and revenue goals.

Track, measure, and take action - all without leaving Countly.

Integrating Countly SDK in your projects

For a detailed description on how to use this SDK check out our documentation.

For information about how to add the SDK to your project, please check this section of the documentation.

You can find minimal SDK integration information for your project in this section of the documentation.

For an example integration of this SDK, you can have a look here.

This SDK supports the following features:

Installation

In the dependencies: section of your pubspec.yaml, add the following line:

  1. dependencies:
  2. countly_flutter: <latest_version>

Usage

  1. import 'package:countly_flutter/countly_flutter.dart';
  2. void main() {
  3. runApp(MaterialApp(home: const MyApp()));
  4. }
  5. class MyApp extends StatefulWidget {
  6. const MyApp({Key? key}) : super(key: key);
  7. @override
  8. State<MyApp> createState() => _MyAppState();
  9. }
  10. class _MyAppState extends State<MyApp> {
  11. @override
  12. void initState() {
  13. super.initState();
  14. // Initialize the SDK once
  15. Countly.isInitialized().then((bool isInitialized) {
  16. if (!isInitialized) {
  17. // Create the configuration with your app key and server URL
  18. final CountlyConfig config = CountlyConfig(SERVER_URL, APP_KEY)..setLoggingEnabled(true);
  19. // In this example, we have logging enabled. For production, disable this.
  20. // Initialize with that configuration
  21. Countly.initWithConfig(config).then((value) {
  22. Countly.start(); // Enables automatic view tracking
  23. });
  24. }
  25. });
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. return Scaffold(
  30. appBar: AppBar(title: Text('Countly Example App')),
  31. body: Center(
  32. child: TextButton(
  33. onPressed: () {
  34. // record an event
  35. Countly.recordEvent({'key': 'Basic Event', 'count': 1});
  36. },
  37. child: Text('Record Event'),
  38. ),
  39. ),
  40. );
  41. }
  42. }

Enabling Automatic Crash Handling

  1. // This will automatically catch all errors that are thrown from within the Flutter framework.
  2. final CountlyConfig config = CountlyConfig(SERVER_URL, APP_KEY)
  3. ..enableCrashReporting()
  4. Countly.initWithConfig(config);

Reporting Exceptions manually

  1. // Manually report a handled or unhandled exception/error to Countly
  2. Countly.logException('This is a manually created exception', true, null);

Recording Events

  1. // Record events (User interactions)
  2. final event = {'key': 'Basic Event', 'count': 1};
  3. Countly.recordEvent({'key': 'Basic Event', 'count': 1});
  4. // you can also record events with segmentation
  5. event['segmentation'] = {'Country': 'Turkey', 'Age': '28'};
  6. Countly.recordEvent({'key': 'Basic Event', 'count': 1});

Recording Views

  1. // Record screen views
  2. final segmentation = {'Country': 'Turkey', 'Age': '28'};
  3. // start recording view with segmentation. NB: Segmentation values are optional.
  4. final String? id = await Countly.instance.views.startView('HomePage', segmentation);
  5. // stop recording view with name with segmentation
  6. await Countly.instance.views.stopViewWithName('HomePage', segmentation);
  7. // stop recording view with ID with segmentation
  8. await Countly.instance.views.stopViewWithID(id, segmentation);
  9. // stop recording all views with segmentation
  10. await Countly.instance.views.stopAllViews(segmentation);

Change Device ID

  1. // A device ID is a unique identifier for your users/device.
  2. // Change device ID with merge.
  3. // Here, the data associated with the previous device ID is merged with the new ID.
  4. await Countly.instance.deviceId.changeWithMerge('123456');
  5. // Change device ID without merge.
  6. // Here, the new device ID is counted as a new device.
  7. await Countly.instance.deviceId.changeWithoutMerge('123456');

Get Device ID Type

  1. // To fetch the device ID type
  2. final DeviceIdType? deviceIdtype = await Countly.instance.deviceId.getIDType();
  3. // DeviceIdType: DEVELOPER_SUPPLIED, SDK_GENERATED, TEMPORARY_ID

User Profile

  1. // To provide information regarding the current user, use this.
  2. final Map<String, Object> options = {
  3. 'name': 'Name of User',
  4. 'username': 'Username',
  5. 'email': 'User Email',
  6. 'phone': 'User Contact number',
  7. 'gender': 'User Gender',
  8. };
  9. Countly.instance.userProfile.setUserProperties(options);
  10. // Increment custom property value by 1
  11. Countly.instance.userProfile.increment('increment');
  12. // Increment custom property value by 10
  13. Countly.instance.userProfile.incrementBy('incrementBy', 10);
  14. // Multiply custom property value by 20
  15. Countly.instance.userProfile.multiply('multiply', 20);
  16. // Save max value between current value and provided value
  17. Countly.instance.userProfile.saveMax('saveMax', 100);
  18. // Save min value between current value and provided value
  19. Countly.instance.userProfile.saveMin('saveMin', 50);
  20. // Set custom property value if it doesn't exist
  21. Countly.instance.userProfile.setOnce('setOnce', '200');
  22. // Add unique value to custom property array
  23. Countly.instance.userProfile.pushUnique('pushUniqueValue', 'morning');
  24. // Add unique value to custom property array if it does not exist
  25. Countly.instance.userProfile.push('pushValue', 'morning');
  26. // Remove value from custom property array
  27. Countly.instance.userProfile.pull('pushValue', 'morning');
  28. // Send/Save provided values to server. After setting values, you must save it by calling save();
  29. Countly.instance.userProfile.save();
  30. // Clear queued operations / modifications
  31. Countly.instance.userProfile.clear();
  1. // For compatibility with data protection regulations, such as GDPR, the Countly
  2. // Flutter SDK allows developers to enable/disable any feature at any time depending
  3. // on user consent.
  4. // Consent values: sessions, events, views, location, crashes, attribution, users, push, starRating, apm, feedback, remoteConfig
  5. // Consent can be enabled during initialization
  6. final CountlyConfig config = CountlyConfig(SERVER_URL, APP_KEY)
  7. ..setConsentEnabled([CountlyConsent.sessions]);
  8. Countly.initWithConfig(config);
  9. // Or after initialization using one of the below methods
  10. // give multiple consent
  11. Countly.giveConsent([CountlyConsent.events, CountlyConsent.views, CountlyConsent.crashes]);
  12. // remove multiple consent
  13. Countly.removeConsent([CountlyConsent.events, CountlyConsent.views, CountlyConsent.crashes]);
  14. // give all consent
  15. Countly.giveAllConsent();
  16. // remove all consent
  17. Countly.removeAllConsent();

Acknowledgements

From 2014 to 2020 it was maintained by Trinisoft Technologies developers (trinisofttechnologies@gmail.com).

Security

Security is very important to us. If you discover any issue regarding security, please disclose the information responsibly by sending an email to security@count.ly and not by creating a GitHub issue.

Badges

If you like Countly, why not use one of our badges and give a link back to us so others know about this wonderful platform?

Countly - Product Analytics

  1. <a href="https://count.ly/f/badge" rel="nofollow"><img style="width:145px;height:60px" src="https://countly.com/badges/dark.svg" alt="Countly - Product Analytics" /></a>

Countly - Product Analytics

  1. <a href="https://count.ly/f/badge" rel="nofollow"><img style="width:145px;height:60px" src="https://countly.com/badges/light.svg" alt="Countly - Product Analytics" /></a>

How can I help you with your efforts?

Glad you asked! For community support, feature requests, and engaging with the Countly Community, please join us at our Discord Server. We’re excited to have you there!

Also, we are on Twitter and LinkedIn if you would like to keep up with Countly related updates.