This repository is no longer maintained or supported. For any inquiries or alternatives, please refer to [email protected]
Stape sGTM SDK implements two main functional parts.
First is a simple event sending which allows to compose an event and send it to Stape Data Client.
SDK API provides a response from the Data Client mapped to a simple model that contains serialized response fields.
Second is a mechanism that tracks events dispatched by the Firebase event SDK.
It hooks Firebase event dispatch and maps Firebase event to Stape Data Client.
After that, it sends it as an ordinary event.
To include the Stape sGTM SDK in your Flutter project, add the following dependency to your pubspec.yaml file:
dependencies:
stape_sdk: ^1.0.0
Ensure you are using the latest version of the Stape sGTM SDK for Flutter.
To use the Stape SDK, you need to create an instance of the Stape
class.
The instance can be created using the Stape.withOption
method.
The method takes an Options
object as a parameter.
import 'package:stape_sdk/stape_sdk.dart';
final Stape stape = Stape.withOption(StapeOptions(domain: "yourdomain.com"));
The Options
object contains data for correct SDK initialization and requires only one
parameter - domain
.
The domain
parameter is a domain name of your sGTM container instance.
Do not include https://
or http://
schemas.
Please do not override the default Options
values if you are not sure what you are doing.
After the Stape instance is created, you can send events to the Stape Data Client.
Stape SDK allows sending data in a couple of ways:
- Using a Map<String, dynamic> collection;
- Using an EventData class.
These two ways are equivalent, and you can use any of them:
stape.sendEvent("event1", {"userId": "cdd1eac3e254", "language": "en"});
stape.sendEventData("event2", EventData(userId: "cdd1eac3e254", language: "en"));
Please extend the EventData
class if you need to send any other data.
Stape SDK allows to decorate Firebase Analytics instance and deliver all sent events to the Stape Data Client as well.
For this purpose you need to use FirebaseAnalyticsAdapter
class.
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:stape_sdk/stape_sdk.dart';
final Stape stape = Stape.withOption(StapeOptions(domain: "yourdomain.com"));
final FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.instance;
final analytics = FirebaseAnalyticsAdapter(stape, firebaseAnalytics);
// Sending events
analytics.logEvent(name: "event3", parameters: {"userId": "cdd1eac3e254", "language": "en"});
The FirebaseAnalyticsAdapter
provides absolutely the same API as the Firebase Analytics instance.
It means that you can replace the provided types without a lot of changes.
If you desire to try the sample app, please follow the next steps:
- Clone the repository;
- Open the project in Android Studio;
- Create a Firebase project with enabled Analytics;
- Generate your own
google-services.json
file and put it into theapp
folder; - Create
stape.properties
file in theapp
folder and put your Stape domain name into it as a value forstape.url
property. Example:server.host=yourdomain.com
; - Rebuild the app.
See LICENSE for more details.
Special thanks to Daniel Lucas Silva for his initial work on this repository!