-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature - Add puglin to support Amplitude
- Loading branch information
Showing
6 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
.packages | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: "761747bfc538b5af34aa0d3fac380f1bc331ec49" | ||
channel: "stable" | ||
|
||
project_type: app | ||
|
||
# Tracks metadata for the flutter migrate command | ||
migration: | ||
platforms: | ||
- platform: root | ||
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
- platform: android | ||
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
- platform: ios | ||
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
- platform: linux | ||
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
- platform: macos | ||
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
- platform: web | ||
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
- platform: windows | ||
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 | ||
|
||
# User provided section | ||
|
||
# List of Local paths (relative to this file) that should be | ||
# ignored by the migrate tool. | ||
# | ||
# Files that are not part of the templates will be ignored by default. | ||
unmanaged_files: | ||
- 'lib/main.dart' | ||
- 'ios/Runner.xcodeproj/project.pbxproj' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# segment_analytics_plugin_amplitude | ||
|
||
`DestinationPlugin` for [amplitude](https://amplitude.com/docs/sdks/sdk-quickstart). Wraps [`amplitude_analytics`](https://pub.dev/packages/amplitude_analytics). | ||
|
||
## Installation | ||
|
||
Manually add this package to your `pubspec.yaml` file. | ||
|
||
```yaml | ||
dependencies: | ||
analytics_plugin_amplitude: | ||
git: | ||
url: https://github.com/segmentio/analytics_flutter | ||
ref: main | ||
path: packages/plugins/plugin_amplitude | ||
``` | ||
## Usage | ||
Follow the [instructions for adding plugins](https://github.com/segmentio/analytics_flutter_#adding-plugins) on the main Analytics client: | ||
In your code where you initialize the analytics client call the `.add(plugin)` method with an `amplitudeDestination` instance. | ||
|
||
```dart | ||
import 'amplitude_options.dart'; | ||
import 'package:segment_analytics/client.dart'; | ||
import 'package:segment_analytics_plugin_amplitude/plugin_amplitude.dart' | ||
show amplitudeDestination; | ||
const writeKey = 'SEGMENT_API_KEY'; | ||
class _MyAppState extends State<MyApp> { | ||
final analytics = createClient(Configuration(writeKey)); | ||
@override | ||
void initState() { | ||
// ... | ||
analytics | ||
.addPlugin(amplitudeDestination()); | ||
} | ||
} | ||
``` | ||
|
||
## Support | ||
|
||
Please use Github issues, Pull Requests, or feel free to reach out to our [support team](https://segment.com/help/). | ||
|
||
## Integrating with Segment | ||
|
||
Interested in integrating your service with us? Check out our [Partners page](https://segment.com/partners/) for more details. | ||
|
||
## License | ||
|
||
``` | ||
MIT License | ||
|
||
Copyright (c) 2023 Segment | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options |
52 changes: 52 additions & 0 deletions
52
packages/plugins/plugin_amplitude/lib/pulgin_amplitude.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:segment_analytics/analytics.dart'; | ||
import 'package:segment_analytics/event.dart'; | ||
import 'package:segment_analytics/plugin.dart'; | ||
import 'package:amplitude_flutter/identify.dart'; | ||
import 'package:amplitude_flutter/amplitude.dart'; | ||
|
||
class AmplitudePlugin extends DestinationPlugin { | ||
final String apiKey; | ||
final String instanceName; | ||
late Amplitude _amplitudeInstance; | ||
|
||
AmplitudePlugin(this.apiKey, this.instanceName) : super('amplitude') { | ||
_amplitudeInstance = Amplitude.getInstance(instanceName: instanceName); | ||
} | ||
|
||
@override | ||
void configure(Analytics analytics) { | ||
super.configure(analytics); | ||
_amplitudeInstance.init(apiKey); | ||
} | ||
|
||
@override | ||
Future<RawEvent?> track(TrackEvent event) async { | ||
await _amplitudeInstance.logEvent(event.event, eventProperties: event.properties); | ||
return event; | ||
} | ||
|
||
@override | ||
Future<RawEvent?> identify(IdentifyEvent event) async { | ||
await _amplitudeInstance.setUserId(event.userId); | ||
if (event.traits != null) { | ||
final Identify identify = Identify(); | ||
await Future.wait(event.traits!.toJson().entries.map((entry) async { | ||
identify.set(entry.key, entry.value.toString()); | ||
})); | ||
_amplitudeInstance.identify(identify); | ||
} | ||
return event; | ||
} | ||
|
||
@override | ||
Future flush() async { | ||
_amplitudeInstance.uploadEvents(); | ||
} | ||
|
||
@override | ||
void reset() { | ||
_amplitudeInstance.setUserId(null); | ||
_amplitudeInstance.clearUserProperties(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: segment_analytics_plugin_amplitude | ||
description: "amplitude plugin." | ||
version: 1.0.0 | ||
homepage: https://github.com/segmentio/analytics_flutter#readme | ||
repository: https://github.com/segmentio/analytics_flutter/tree/main/packages/plugins/plugin_amplitude#readme | ||
issue_tracker: https://github.com/segmentio/analytics_flutter/issues | ||
|
||
environment: | ||
sdk: '>=2.19.3 <4.0.0' | ||
flutter: ">=1.17.0" | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
segment_analytics: ^1.0.0 | ||
json_annotation: ^4.8.0 | ||
amplitude_flutter: ^3.13.0 | ||
|
||
dev_dependencies: | ||
build_runner: ^2.3.3 | ||
json_serializable: ^6.6.0 | ||
flutter_test: | ||
sdk: flutter | ||
flutter_lints: ^2.0.0 | ||
|
||
flutter: | ||
|