Giter Club home page Giter Club logo

snowplow-flutter-tracker's Introduction

Flutter Analytics for Snowplow

early-release Build Status Release License

Snowplow is a scalable open-source platform for rich, high quality, low-latency data collection. It is designed to collect high quality, complete behavioral data for enterprise business.

To find out more, please check out the Snowplow website and our documentation.

Snowplow Flutter Tracker Overview

The Snowplow Flutter Tracker allows you to add analytics to your Flutter apps when using a Snowplow pipeline.

With this tracker you can collect granular event-level data as your users interact with your Flutter applications. It is build on top of Snowplow's native iOS and Android and web trackers, in order to support the full range of out-of-the-box Snowplow events and tracking capabilities.

Technical documentation can be found for each tracker in our Documentation.

Features

Feature Android iOS Web
Manual tracking of events: screen views, self-describing, structured, timing, consent granted and withdrawal
Automatic tracking of views events from Navigator API
Adding custom context entities to events
Support for multiple trackers
Configurable subject properties partly
Session context entity added to events
Geo-location context entity
Mobile platform context entity
Web page context entity
Configurable GDPR context entity
Lifecycle autotracking
Engagement tracking (activity tracking on Web, mobile screen engagement on mobile)
Media playback tracking

Quick Start

Installation

Add the Snowplow tracker as a dependency to your Flutter application:

flutter pub add snowplow_tracker

This will add a line with the dependency like this to your pubspec.yaml:

dependencies:
    snowplow_tracker: ^0.7.1

Import the package into your Dart code:

import 'package:snowplow_tracker/snowplow_tracker.dart'

Installation on Web

If using the tracker within a Flutter app for Web, you will also need to import the Snowplow JavaScript Tracker in your index.html file. Please load the JS tracker with the Snowplow tag as described in the official documentation. Do not change the global function name snowplow that is used to access the tracker – the Flutter APIs assume that it remains the default as shown in documentation.

Make sure to use JavaScript tracker version 3.5 or newer. You may also refer to the example project in the Flutter tracker repository to see this in action.

Using the Tracker

Instantiate a tracker using the Snowplow.createTracker function. You may create the tracker in the initState() of your main widget. The function takes two required arguments: namespace and endpoint. Tracker namespace identifies the tracker instance; you may create multiple trackers with different namespaces. The endpoint is the URI of the Snowplow collector to send the events to. There are additional optional arguments to configure the tracker, please refer to the documentation for a complete specification.

SnowplowTracker tracker = await Snowplow.createTracker(
    namespace: 'ns1',
    endpoint: 'http://...'
);

To track events, simply instantiate their respective types (e.g., ScreenView, SelfDescribing, Structured) and pass them to the tracker.track or Snowplow.track methods. Please refer to the documentation for specification of event properties.

// Tracking a screen view event
tracker.track(ScreenView(
    id: '2c295365-eae9-4243-a3ee-5c4b7baccc8f',
    name: 'home',
    type: 'full',
    transitionType: 'none'));

// Tracking a page view event – only supported on the Web
tracker.track(PageView(title: 'Page Title'));

// Tracking a self-describing event
tracker.track(SelfDescribing(
    schema: 'iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1',
    data: {'targetUrl': 'http://a-target-url.com'}
));

// Tracking a structured event
tracker.track(Structured(
    category: 'shop',
    action: 'add-to-basket',
    label: 'Add To Basket',
    property: 'pcs',
    value: 2.00,
));

// Tracking an event using the Snowplow interface and tracker namespace
Snowplow.track(
    Structured(category: 'shop', action: 'add-to-basket'),
    tracker: 'ns1' // namespace of initialized tracker
);

// Adding context to an event
tracker.track(
    Structured(category: 'shop', action: 'add-to-basket'),
    contexts: [
        const SelfDescribing(
            schema: 'iglu:org.schema/WebPage/jsonschema/1-0-0',
            data: {'keywords': ['tester']}
        )
    ]);

Find Out More

Technical Docs Setup Guide
i1 i2
Technical Docs Setup Guide

Maintainers

Contributing
i4
Contributing

Maintainer Quick Start

Assuming Flutter SDK is set up and Snowplow Micro is running on your computer.

Clone Repository

git clone https://github.com/snowplow/snowplow-flutter-tracker.git

Example App

The tracker comes with a demo app that shows it in use. It is a simple app with list of buttons for triggering different types of events. The project is located in the example subfolder.

Running the example app on Android/iOS:

  1. Change into the project folder and cd example
  2. Run the app (replace the Snowplow Micro URI with your IP address and set your iPhone or Android simulator name or remove to use default):
flutter run --dart-define=ENDPOINT=http://192.168.100.127:9090 -d "iPhone 13 Pro"

To run the example app on Web:

  1. Download ChromeDriver and launch it using chromedriver --port=4444
  2. Change into the project folder and cd example
  3. Run the app (replace the Snowplow Micro URI with your IP address):
flutter run --dart-define=ENDPOINT=http://0.0.0.0:9090 -d Chrome

Alternatively, if you use Visual Studio Code you may also run the example app using the "Run Example App" target (update your IP address in .vscode/launch.json).

Testing

The tracker functionality is verified using unit and integration tests. Unit tests test individual components of the tracker in isolation and do not make any external network requests. Integration tests use a Snowplow Micro instance to verify end-to-end tracking of events.

The unit tests are located in the tests subfolder in the root of the project. Having installed the Flutter SDK, run the tests using flutter test (or run them directly from Visual Studio Code).

The integration tests are located in the example/integration_test subfolder. These tests make use of the example app to provide end-to-end testing of the tracker.

Running the integration tests on Android/iOS:

  1. Change into the project folder and cd example
  2. Run the integration tests (replace the Snowplow Micro URI with your IP address and set your iPhone or Android simulator name or remove to use default):
flutter test integration_test --dart-define=ENDPOINT=http://192.168.0.20:9090 -d "iPhone 13 Pro"

Alternatively, you may also run the integration tests directly from Visual Studio Code.

To run the integration tests on Web:

  1. Download ChromeDriver and launch it using chromedriver --port=4444
  2. Change into the project folder and cd example
  3. Run the integration tests (replace the Snowplow Micro URI with your IP address):
./tool/e2e_tests.sh http://0.0.0.0:9090 "-d web-server"

Copyright and License

The Snowplow Flutter Tracker is copyright 2022-present Snowplow Analytics Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

snowplow-flutter-tracker's People

Contributors

matus-tomlein avatar mscwilson avatar petermnt avatar

Stargazers

 avatar Shashank Arora avatar iroïd avatar Denes avatar

Watchers

 avatar  avatar John Piekos avatar Andy Hay avatar Josh avatar  avatar Peter Zhu avatar Peter Perlepes avatar Piotr Poniedziałek avatar  avatar  avatar

snowplow-flutter-tracker's Issues

Android: 'kotlin-android-extensions' plugin is deprecated

Good morning,

We have a couple Flutter apps (currently in the stores) which depend on snowplow_tracker.
The latest version (0.3.0) of snowplow_tracker has an Android dependency to the kotlin-android-extensions plugin, which is deprecated:
https://developer.android.com/topic/libraries/view-binding/migration

I've forked this repository and pushed changes in a branch from which a Pull Request could be opened:
jeremie-movify@c9e6866#diff-197b190e4a3512994d2cebed8aff5479ff88e136b8cc7a4b148ec9c3945bd65a

The removal of the said plugin doesn't remove any existing functionality. Instead, it allows us to use the latest version of Flutter (3.10).

Cheers!

Upgrade min Flutter, Dart and Android SDK versions and upgrade dependencies

  • Upgrade min Dart SDK from 2.15 to 2.17
  • Upgrade minimum Flutter version from 2.8 to 3.0 – this was required as a result of updating the other dependencies
  • Change in Android SDK versions:
    • Min SDK version from 16 to 21
    • Compile SDK version from 30 to 31
  • Kotlin version from 1.4 to 1.7
  • OkHttp from 4.9 to 4.10
  • Upgrade flutter_lints from 1 to 2

Update SDK constraint to <4.0.0

Reported by dart analyze:

* The declared SDK constraint is '>=2.17.0 <3.0.0', this is interpreted as '>=2.17.0 <4.0.0'.
  
  Consider updating the SDK constraint to:
  
  environment:
    sdk: '>=2.17.0 <4.0.0'

Enable screen and application context on mobile

Currently the tracker does not make use of the features of the Android and iOS trackers to add the screen and application context entities to events – they are disabled by default. However, these entities are used by the mobile data model so we should track them if possible.

We should add their booleans to the TrackerConfiguration similar to the other mobile trackers and enable them by default on mobile.

They will be ignored on the Web as the JavaScript tracker does not provide them but I think they are still worth tracking on mobile.

Fix publish action

The publish action seems to be hanging due to failed authorization. Deploying locally works so we may need to refresh auth tokens.

HTTP Headers

Hello Snowplow,

is it possible to append some HTTP headers to the requests? Unfortunately, I cannot find an interface for something like that but our internal tracking team relies on parsing some information embedded in the HTTP headers.

Add media tracking APIs to the tracker

Add functions to track media events using the Flutter tracker. On the background this should fall back to the media tracking APIs in the iOS/Android/JS trackers.

No automated tracking will be implemented here, the tracker will just expose functions to track media events.

Remove deprecated setMockMethodCallHandler from tests

Reported by dart analyze:

     info - test/snowplow_test.dart:39:13 - 'setMockMethodCallHandler' is deprecated and shouldn't be used. Use tester.binding.defaultBinaryMessenger.setMockMethodCallHandler or TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler instead. Pass the channel as the first argument. This feature was deprecated after v3.9.0-19.0.pre. Try replacing the use of the deprecated member with the replacement. - deprecated_member_use
  [...]deprecated_member_use
     info - test/tracker_test.dart:42:13 - 'setMockMethodCallHandler' is deprecated and shouldn't be used. Use tester.binding.defaultBinaryMessenger.setMockMethodCallHandler or TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler instead. Pass the channel as the first argument. This feature was deprecated after v3.9.0-19.0.pre. Try replacing the use of the deprecated member with the replacement. - deprecated_member_use

Fatal Exception: java.lang.ExceptionInInitializerError

Describe the bug
Fatal Exception: java.lang.ExceptionInInitializerError

To Reproduce
unable to reproduce in dev environment, facing issue in prod, reported in the firebase crashlog.

Expected behavior
should not throw an error

Screenshots
If applicable, add screenshots to help explain your problem.
Screenshot 2024-07-12 at 13 00 55

Device informatoin (please complete the following information):

  • Device: Pixel 6
  • OS: Android 14
  • Version snowplow_tracker: ^0.7.1 (flutter)

Additional context
stacktrace.txt

Add any other context about the problem here.

Configure custom POST path

Unlike your iOS, Android (customPostPath) and web (postPath) SDKs, it seems to be impossible to override the path with a custom path. Our infrastructure follows the suggested setup where we use a custom path (instead of com.snowplow) to hopefully prevent ad/tracking blockers from intercepting the analytics calls, yet from Flutter we cannot set our own path and thus it is impossible to track. This is a blocker issue for us.

Please add support for setting the postPath/customPath from Flutter.

Offline Capability

Hello Snowplow Team,

does the SDK support a caching logic when being offline? As far as I can tell, I cannot set timestamps on my own, the SDK takes care of it. Let's say I am offline and I am collecting some ScreenViews. As soon as I'm online again, we send the collected events to the collection endpoint. The automatically added timestamps would be incorrect, right?

Add anonymous tracking features

Anonymous tracking is a feature currently implemented in the JavaScript, iOS, and Android trackers that enables anonymising various user and session identifiers. It affects the following user and session identifiers:

  1. Client-side user identifiers: domain_userid (equivalent to client_session.userId in session context). On mobile, there are also the IDFA identifiers in the mobile_context platform context entity.
  2. Client-side session identifiers: domain_sessionid (equivalent to client_session.sessionId in session context)
  3. Server-side user identifiers: network_userid and user_ipaddress

There are several levels to the anonymisation depending on which of the three categories are affected:

1. Full client-side anonymisation

In this case, both the client-side user identifiers as well as the client-side session identifiers are anonymised.

Current options in mobile trackers

One could disable tracking both the client_session and mobile_context context entities:

trackerConfig.sessionContext = false
trackerConfig.platformContext = false

TODO in Flutter tracker

Disabling the platform context altogether may be a bit wasteful as there is other information (e.g., memory usage, carrier, OS) that are not user or session identifiers (although they could be used for fingerprinting). We could provide an option to only disable the IDFA identifiers in the platform context:

trackerConfig.userAnonymisation = true

This could set them to null (they are not required in the platform context schema).

2. Client-side anonymisation with session tracking

In this case, client-side user identifiers should be disabled but session identifiers should still be tracked.

Current options in mobile trackers

This is currently not possible in the mobile trackers.

TODO in Flutter tracker

We could provide an option to enable session context while disabling all user identifiers (both the ones in client_session and mobile_context context entities):

trackerConfig.sessionContext = true
trackerConfig.userAnonymisation = true

The userId in client_session is a required property, so this could always set it to 00000000-0000-0000-0000-000000000000.

3. Server-side anonymisation

This disables setting the server-side cookies with network_userid and also anonymizes the user IP address.

Current options in mobile trackers

This is currently not possible in the mobile trackers.

TODO in Flutter tracker

We could add an option to the tracker configuration:

emitterConfig.serverAnonymisation = true

This would set the SP-Anonymous: * HTTP header for requests going to the Collector. The collector will take care of not setting the request headers and anonymizing the IP address.

Pod Installation Issue

I am using snowplow_tracker 0.3.0 and upon building I am getting the following error

[!] CocoaPods could not find compatible versions for pod "SnowplowTracker":
  In Podfile:
    snowplow_flutter_tracker (from `.symlinks/plugins/snowplow_flutter_tracker/ios`) was resolved to 0.0.1, which depends on
      SnowplowTracker (~> 1.6.2)

    snowplow_tracker (from `.symlinks/plugins/snowplow_tracker/ios`) was resolved to 0.3.0, which depends on
      SnowplowTracker (~> 4.0)

It looks like the 1.6.2 needs to be updated.
Is this package still being developed/supported, or should I fork and make the change on my own?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.