flutter_acpanalytics 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

flutter_acpanalytics #

pub package Build License

flutter_acpanalytics is a flutter plugin for the iOS and Android AEP Analytics SDK to allow for integration with flutter applications. Functionality to enable the Analytics extension is provided entirely through Dart documented below.

Installation #

Install instructions for this package can be found here.

Note: After you have installed the SDK, don't forget to run pod install in your ios directory to link the libraries to your Xcode project.

Tests #

Run:

flutter test

Usage #

Analytics #

Importing the SDK:
import 'package:flutter_acpanalytics/flutter_acpanalytics.dart';
Getting the SDK version:
String version = await FlutterACPAnalytics.extensionVersion;
Registering the extension with ACPCore:

Note: It is required to initialize the SDK via native code inside your AppDelegate and MainApplication for iOS and Android respectively. For more information see how to initialize Core.

iOS

Swift

import ACPAnalytics

ACPAnalytics.registerExtension()

Objective-C

#import "ACPAnalytics.h"

[ACPAnalytics registerExtension];
Android:
import com.adobe.marketing.mobile.Analytics;

Analytics.registerExtension();
Get the tracking identifier:
String trackingId;

try {
	trackingId = await FlutterACPAnalytics.trackingIdentifier;
} on PlatformException {
	log("Failed to get the tracking identifier");
}
Send queued hits:
FlutterACPAnalytics.sendQueuedHits();
Get the queue size:
int queueSize;

try {
	queueSize = await FlutterACPAnalytics.queueSize;
} on PlatformException {
	log("Failed to get the queue size");
}
Clear queued hits:
FlutterACPAnalytics.clearQueue();
Set the custom visitor identifier:
FlutterACPAnalytics.setVisitorIdentifier("vid");
Get the custom visitor identifier:
String visitorId;

try {
	visitorId = await FlutterACPAnalytics.visitorIdentifier;
} on PlatformException {
	visitorId = "Failed to get the visitor identifier";
}
Track app actions:
FlutterACPCore.trackAction("myAction",  data: {"key1": "value1"});
Track app states:
FlutterACPCore.trackState("myState",  data: {"key1": "value1"});

Contributing #

See CONTRIBUTING

License #

See LICENSE

1.0.0 #

  • Initial release candidate

1.0.0-beta.4 #

  • Update docs.

1.0.0-beta.3 #

  • Fix install instructions.
  • Fixed a bug when installing with pod install.

1.0.0-beta.2 #

  • Metadata updates.

1.0.0-beta.1 #

  • Initial beta release.

example/lib/main.dart

/*
Copyright 2020 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
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 REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
import 'dart:developer';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_acpcore/flutter_acpcore.dart';
import 'package:flutter_acpanalytics/flutter_acpanalytics.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  int _queueSize = 0;
  String _trackingId = '';
  String _visitorId = '';

  @override
  void initState() {
    super.initState();
    initPlatformState();
    getQueueSize();
    getTrackingIdentifier();
    getVisitorIdentifier();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await FlutterACPAnalytics.extensionVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> getQueueSize() async {
    int queueSize;
    try {
      queueSize = await FlutterACPAnalytics.queueSize;
    } on PlatformException {
      log("Failed to get the queue size");
      queueSize = 0;
    }

    if (!mounted) return;
    setState(() {
      _queueSize = queueSize;
    });
  }

  Future<void> getTrackingIdentifier() async {
    String trackingId;
    try {
      trackingId = await FlutterACPAnalytics.trackingIdentifier;
    } on PlatformException {
      log("Failed to get the tracking identifier");
    }

    if (!mounted) return;
    setState(() {
      _trackingId = trackingId;
    });
  }

  Future<void> getVisitorIdentifier() async {
    String visitorId;
    try {
      visitorId = await FlutterACPAnalytics.visitorIdentifier;
    } on PlatformException {
      visitorId = "Failed to get the visitor identifier";
    }

    if (!mounted) return;
    setState(() {
      _visitorId = visitorId;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(children: <Widget>[
            Text('ACPAnalytics version = $_platformVersion\n'),
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  RaisedButton(
                    child: Text("ACPCore.trackState(...)"),
                    onPressed: () => FlutterACPCore.trackState("myState",
                        data: {"key1": "value1"}),
                  ),
                  RaisedButton(
                    child: Text("ACPCore.trackAction(...)"),
                    onPressed: () => FlutterACPCore.trackAction("myAction",
                        data: {"key1": "value1"}),
                  ),
                ]),
            RaisedButton(
              child: Text("ACPAnalytics.sendQueuedHits()"),
              onPressed: () => FlutterACPAnalytics.sendQueuedHits(),
            ),
            RaisedButton(
              child: Text("ACPAnalytics.clearQueue()"),
              onPressed: () => FlutterACPAnalytics.clearQueue(),
            ),
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  RaisedButton(
                    child: Text("ACPAnalytics.getQueueSize()"),
                    onPressed: () => getQueueSize(),
                  ),
                  Text('Queue size = $_queueSize\n'),
                ]),
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  RaisedButton(
                    child: Text("ACPAnalytics.getTrackingIdentifier()"),
                    onPressed: () => getTrackingIdentifier(),
                  ),
                  Text('Tracking Id = $_trackingId\n'),
                ]),
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  RaisedButton(
                    child: Text("ACPAnalytics.getVisitorIdentifier()"),
                    onPressed: () => getVisitorIdentifier(),
                  ),
                  Text('Visitor Id = $_visitorId\n'),
                ]),
            RaisedButton(
              child: Text("ACPAnalytics.setVisitorIdentifier(vid)"),
              onPressed: () => FlutterACPAnalytics.setVisitorIdentifier("vid"),
            ),
          ]),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_acpanalytics: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_acpanalytics/flutter_acpanalytics.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_acpcore >=1.0.0 <2.0.0 1.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test