flutter_acpcore 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

flutter_acpcore #

pub package Build License

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

Contents #

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.

After you have installed Core, you can install additional AEP Flutter extensions.

ExtensionPackage
Analyticspub package
Griffonpub package

Tests #

Run:

flutter test

Usage #

Initializing: #

Initializing the SDK should be done in native code, documentation on how to initalize the SDK can be found here. The linked documentation initalizes the User Profile extension which is not required or supported in Flutter.

Once you have added the initialization code to your app, be sure to set the SDK wrapper type to Flutter before you start the SDK.

iOS:

Swift:

ACPCore.setWrapperType(.flutter)

Objective-C:

[ACPCore setWrapperType:ACPMobileWrapperTypeFlutter];
Android:
MobileCore.setWrapperType(WrapperType.FLUTTER);

Core #

Importing Core:
import 'package:flutter_acpcore/flutter_acpcore.dart';
Getting Core version:
String version = await FlutterACPCore.extensionVersion;
Updating the SDK configuration:
FlutterACPCore.updateConfiguration({"key" : "value"});
Controlling the log level of the SDK:
import 'package:flutter_acpcore/src/acpmobile_logging_level.dart';

FlutterACPCore.setLogLevel(ACPLoggingLevel.ERROR);
FlutterACPCore.setLogLevel(ACPLoggingLevel.WARNING);
FlutterACPCore.setLogLevel(ACPLoggingLevel.DEBUG);
FlutterACPCore.setLogLevel(ACPLoggingLevel.VERBOSE);
Getting the current privacy status:
import 'package:flutter_acpcore/src/acpmobile_privacy_status.dart';

ACPPrivacyStatus result;

try {
  result = await FlutterACPCore.privacyStatus;
} on PlatformException {
  log("Failed to get privacy status");
}
Setting the privacy status:
import 'package:flutter_acpcore/src/acpmobile_privacy_status.dart';

FlutterACPCore.setPrivacyStatus(ACPPrivacyStatus.OPT_IN);
FlutterACPCore.setPrivacyStatus(ACPPrivacyStatus.OPT_OUT);
FlutterACPCore.setPrivacyStatus(ACPPrivacyStatus.UNKNOWN);
Getting the SDK identities:
String result = "";

try {
  result = await FlutterACPCore.sdkIdentities;
} on PlatformException {
  log("Failed to get sdk identities");
}
Dispatching an Event Hub event:
import 'package:flutter_acpcore/src/acpextension_event.dart';

final ACPExtensionEvent event = ACPExtensionEvent.createEvent("eventName", "eventType", "eventSource", {"testDataKey": "testDataValue"});

bool result;
try {
  result = await FlutterACPCore.dispatchEvent(event);
} on PlatformException catch (e) {
  log("Failed to dispatch event '${e.message}''");
}
Dispatching an Event Hub event with callback:
import 'package:flutter_acpcore/src/acpextension_event.dart';

ACPExtensionEvent result;
final ACPExtensionEvent event ACPExtensionEvent.createEvent("eventName", "eventType", "eventSource", {"testDataKey": "testDataValue"});

try {
  result = await FlutterACPCore.dispatchEventWithResponseCallback(event);
} on PlatformException catch (e) {
  log("Failed to dispatch event '${e.message}''");
}
Dispatching an Event Hub response event:
import 'package:flutter_acpcore/src/acpextension_event.dart';

bool result;
final ACPExtensionEvent responseEvent = ACPExtensionEvent.createEvent("eventName", "eventType", "eventSource", {"testDataKey": "testDataValue"});
final ACPExtensionEvent requestEvent = ACPExtensionEvent.createEvent("eventName", "eventType", "eventSource", {"testDataKey": "testDataValue"});

try {
  result = await FlutterACPCore.dispatchResponseEvent(responseEvent, requestEvent);
} on PlatformException catch (e) {
  log("Failed to dispatch events '${e.message}''");
}

Identity #

Importing Identity:
import 'package:flutter_acpcore/flutter_acpidentity.dart';
Getting Identity version:
String version = await FlutterACPIdentity.extensionVersion;
Sync Identifier:
import 'package:flutter_acpcore/src/acpmobile_visitor_id.dart';

FlutterACPIdentity.syncIdentifier("identifierType", "identifier", ACPMobileVisitorAuthenticationState.AUTHENTICATED);
Sync Identifiers:
FlutterACPIdentity.syncIdentifiers({"idType1":"idValue1",
                                    "idType2":"idValue2",
                                    "idType3":"idValue3"});
Sync Identifiers with Authentication State:
import 'package:flutter_acpcore/src/acpmobile_visitor_id.dart';

FlutterACPIdentity.syncIdentifiersWithAuthState({"idType1":"idValue1", "idType2":"idValue2", "idType3":"idValue3"}, ACPMobileVisitorAuthenticationState.AUTHENTICATED);

Note: ACPMobileVisitorAuthenticationState is defined as:

enum ACPMobileVisitorAuthenticationState {UNKNOWN, AUTHENTICATED, LOGGED_OUT}
Append visitor data to a URL:
String result = "";

try {
  result = await FlutterACPIdentity.appendToUrl("www.myUrl.com");
} on PlatformException {
  log("Failed to append URL");
}
Setting the advertising identifier:
FlutterACPCore.setAdvertisingIdentifier("ad-id");
Get visitor data as URL query parameter string:
String result = "";

try {
  result = await FlutterACPIdentity.urlVariables;
} on PlatformException {
  log("Failed to get url variables");
}
Get Identifiers:
List<ACPMobileVisitorId> result;

try {
  result = await FlutterACPIdentity.identifiers;
} on PlatformException {
  log("Failed to get identifiers");
}
Get Experience Cloud IDs:
String result = "";

try {
  result = await FlutterACPIdentity.experienceCloudId;
} on PlatformException {
  log("Failed to get experienceCloudId");
}
ACPMobileVisitorId Class:
import 'package:flutter_acpcore/src/acpmobile_visitor_id.dart';

class ACPMobileVisitorId {
  String get idOrigin;
  String get idType;
  String get identifier;
  ACPMobileVisitorAuthenticationState get authenticationState;
}

Lifecycle #

Note: It is required to implement Lifecycle in native Android and iOS code.

Signal #

Importing Signal:
import 'package:flutter_acpcore/flutter_acpsignal.dart';
Getting Signal version:
String version = await FlutterACPSignal.extensionVersion;

Contributing #

See CONTRIBUTING

License #

See LICENSE

1.0.0 #

  • Initial release candidate

1.0.0-beta.6 #

1.0.0-beta.5 #

  • Update docs.

1.0.0-beta.4 #

  • Improve install instructions.

1.0.0-beta.3 #

  • Fix install instructions.

1.0.0-beta.2 #

  • Metadata updates.

1.0.0-beta.1 #

  • Initial beta release.

example/lib/main.dart

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_acpcore/flutter_acpidentity.dart';
import 'package:flutter_acpcore/flutter_acplifecycle.dart';
import 'package:flutter_acpcore/flutter_acpsignal.dart';
import 'package:flutter_acpcore/src/acpmobile_visitor_id.dart';
import 'package:flutter_acpcore/src/acpextension_event.dart';
import 'package:flutter_acpcore/src/acpmobile_logging_level.dart';
import 'package:flutter_acpcore/src/acpmobile_privacy_status.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _coreVersion = 'Unknown';
  String _identityVersion = 'Unknown';
  String _lifecycleVersion = 'Unknown';
  String _signalVersion = 'Unknown';
  String _appendToUrlResult = "";
  String _experienceCloudId = "";
  String _getUrlVariablesResult = "";
  String _getIdentifiersResult = "";
  String _sdkIdentities = "";
  String _privacyStatus = "";

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String coreVersion, lifecycleVersion, signalVersion, identityVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      coreVersion = await FlutterACPCore.extensionVersion;
      identityVersion = await FlutterACPIdentity.extensionVersion;
      lifecycleVersion = await FlutterACPLifecycle.extensionVersion;
      signalVersion = await FlutterACPSignal.extensionVersion;
    } on PlatformException {
      log("Failed to get extension versions");
    }

    // 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(() {
      _coreVersion = coreVersion;
      _identityVersion = identityVersion;
      _lifecycleVersion = lifecycleVersion;
      _signalVersion = signalVersion;
    });
  }

  Future<void> appendUrl() async {
    String result = "";

    try {
      result = await FlutterACPIdentity.appendToUrl("www.myUrl.com");
    } on PlatformException {
      log("Failed to append URL");
    }

    if (!mounted) return;
    setState(() {
      _appendToUrlResult = result;
    });
  }

  Future<void> getExperienceCloudId() async {
    String result = "";

    try {
      result = await FlutterACPIdentity.experienceCloudId;
    } on PlatformException {
      log("Failed to get experienceCloudId");
    }

    if (!mounted) return;
    setState(() {
      _experienceCloudId = result;
    });
  }

  Future<void> syncIdentifiers() async {
    FlutterACPIdentity.syncIdentifiers(
        {"idType1": "idValue1", "idType2": "idValue2", "idType3": "idValue3"});
  }

  Future<void> syncIdentifiersWithAuthState() async {
    FlutterACPIdentity.syncIdentifiersWithAuthState(
        {"idType1": "idValue1", "idType2": "idValue2", "idType3": "idValue3"},
        ACPMobileVisitorAuthenticationState.AUTHENTICATED);
  }

  Future<void> syncIdentifier() async {
    FlutterACPIdentity.syncIdentifier("idType1", "idValue1",
        ACPMobileVisitorAuthenticationState.AUTHENTICATED);
  }

  Future<void> getUrlVariables() async {
    String result = "";

    try {
      result = await FlutterACPIdentity.urlVariables;
    } on PlatformException {
      log("Failed to get url variables");
    }

    if (!mounted) return;
    setState(() {
      _getUrlVariablesResult = result;
    });
  }

  Future<void> getSdkIdentities() async {
    String result = "";

    try {
      result = await FlutterACPCore.sdkIdentities;
    } on PlatformException {
      log("Failed to get sdk identities");
    }

    if (!mounted) return;
    setState(() {
      _sdkIdentities = result;
    });
  }

  Future<void> getPrivacyStatus() async {
    ACPPrivacyStatus result;

    try {
      result = await FlutterACPCore.privacyStatus;
    } on PlatformException {
      log("Failed to get privacy status");
    }

    if (!mounted) return;
    setState(() {
      _privacyStatus = result.value;
    });
  }

  Future<void> getIdentifiers() async {
    List<ACPMobileVisitorId> result;

    try {
      result = await FlutterACPIdentity.identifiers;
    } on PlatformException {
      log("Failed to get identifiers");
    }

    if (!mounted) return;
    setState(() {
      _getIdentifiersResult = result.toString();
    });
  }

  Future<void> setAdvertisingIdentifier() async {
    FlutterACPCore.setAdvertisingIdentifier("ad-id");
  }

  Future<void> dispatchEvent() async {
    bool result;
    final ACPExtensionEvent event = ACPExtensionEvent({
      "eventName": "testEventName",
      "eventType": "testEventType",
      "eventSource": "testEventSource",
      "eventData": {"eventDataKey": "eventDataValue"}
    });
    try {
      result = await FlutterACPCore.dispatchEvent(event);
    } on PlatformException catch (e) {
      log("Failed to dispatch event '${e.message}''");
    }
  }

  Future<void> dispatchEventWithResponseCallback() async {
    ACPExtensionEvent result;
    final ACPExtensionEvent event = ACPExtensionEvent({
      "eventName": "testEventName",
      "eventType": "testEventType",
      "eventSource": "testEventSource",
      "eventData": {"eventDataKey": "eventDataValue"}
    });
    try {
      result = await FlutterACPCore.dispatchEventWithResponseCallback(event);
    } on PlatformException catch (e) {
      log("Failed to dispatch event '${e.message}''");
    }
  }

  Future<void> dispatchResponseEvent() async {
    bool result;
    final ACPExtensionEvent responseEvent = ACPExtensionEvent({
      "eventName": "testresponseEvent",
      "eventType": "testresponseEvent",
      "eventSource": "testEventSource",
      "eventData": {"eventDataKey": "eventDataValue"}
    });
    final ACPExtensionEvent requestEvent = ACPExtensionEvent({
      "eventName": "testrequestEvent",
      "eventType": "testrequestEvent",
      "eventSource": "testEventSource",
      "eventData": {"eventDataKey": "eventDataValue"}
    });
    try {
      result = await FlutterACPCore.dispatchResponseEvent(
          responseEvent, requestEvent);
    } on PlatformException catch (e) {
      log("Failed to dispatch events '${e.message}''");
    }
  }

  Future<void> downloadRules() async {
    FlutterACPCore.downloadRules();
  }

  // UTIL
  RichText getRichText(String label, String value) {
    return new RichText(
      text: new TextSpan(
        // Note: Styles for TextSpans must be explicitly defined.
        // Child text spans will inherit styles from parent
        style: new TextStyle(
          fontSize: 14.0,
          color: Colors.black,
        ),
        children: <TextSpan>[
          new TextSpan(
              text: label, style: new TextStyle(fontWeight: FontWeight.bold)),
          new TextSpan(text: value),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          bottom: TabBar(
            tabs: [
              Text('Core'),
              Text('Identity'),
            ],
          ),
          title: Text('Flutter ACPCore'),
        ),
        body: TabBarView(
          children: [
            Center(
              child: ListView(shrinkWrap: true, children: <Widget>[
                getRichText('ACPCore extension version: ', '$_coreVersion\n'),
                getRichText(
                    'ACPLifecycle extension version: ', '$_lifecycleVersion\n'),
                getRichText(
                    'ACPSignal extension version: ', '$_signalVersion\n'),
                getRichText('SDK Identities = ', '$_sdkIdentities\n'),
                getRichText('Privacy status = ', '$_privacyStatus\n'),
                RaisedButton(
                  child: Text("FlutterACPCore.sdkIdentities"),
                  onPressed: () => getSdkIdentities(),
                ),
                RaisedButton(
                  child: Text("FlutterACPCore.privacyStatus"),
                  onPressed: () => getPrivacyStatus(),
                ),
                RaisedButton(
                  child: Text("FlutterACPCore.setLogLevel"),
                  onPressed: () =>
                      FlutterACPCore.setLogLevel(ACPLoggingLevel.ERROR),
                ),
                RaisedButton(
                  child: Text("FlutterACPCore.setPrivacyStatus(...)"),
                  onPressed: () =>
                      FlutterACPCore.setPrivacyStatus(ACPPrivacyStatus.OPT_IN),
                ),
                RaisedButton(
                  child: Text("FlutterACPCore.updateConfiguration(...)"),
                  onPressed: () =>
                      FlutterACPCore.updateConfiguration({"key": "value"}),
                ),
                RaisedButton(
                  child: Text("FlutterACPCore.setAdvertisingIdentifier(...)"),
                  onPressed: () => setAdvertisingIdentifier(),
                ),
                RaisedButton(
                  child: Text("FlutterACPCore.dispatchEvent(...)"),
                  onPressed: () => dispatchEvent(),
                ),
                RaisedButton(
                  child: Text(
                      "FlutterACPCore.dispatchEventWithResponseCallback(...)"),
                  onPressed: () => dispatchEventWithResponseCallback(),
                ),
                RaisedButton(
                  child: Text("FlutterACPCore.dispatchResponseEvent(...)"),
                  onPressed: () => dispatchResponseEvent(),
                ),
                RaisedButton(
                  child: Text("FlutterACPCore.downloadRules()"),
                  onPressed: () => downloadRules(),
                ),
              ]),
            ),
            Center(
              child: ListView(shrinkWrap: true, children: <Widget>[
                getRichText(
                    'ACPIdentity extension version: ', '$_identityVersion\n'),
                getRichText('Append to URL result = ', '$_appendToUrlResult\n'),
                getRichText('Experience Cloud ID = ', '$_experienceCloudId\n'),
                getRichText(
                    'Get URL variables result = ', '$_getUrlVariablesResult\n'),
                getRichText('Identifiers = ', '$_getIdentifiersResult\n'),
                RaisedButton(
                  child: Text("FlutterACPIdentity.appendToUrl(...)"),
                  onPressed: () => appendUrl(),
                ),
                RaisedButton(
                  child: Text("FlutterACPIdentity.identifiers"),
                  onPressed: () => getIdentifiers(),
                ),
                RaisedButton(
                  child: Text("FlutterACPIdentity.experienceCloudId"),
                  onPressed: () => getExperienceCloudId(),
                ),
                RaisedButton(
                  child: Text("FlutterACPIdentity.syncIdentifier(...)"),
                  onPressed: () => syncIdentifier(),
                ),
                RaisedButton(
                  child: Text("FlutterACPIdentity.syncIdentifiers(...)"),
                  onPressed: () => syncIdentifiers(),
                ),
                RaisedButton(
                  child: Text(
                      "FlutterACPIdentity.syncIdentifiersWithAuthState(...)"),
                  onPressed: () => syncIdentifiersWithAuthState(),
                ),
                RaisedButton(
                  child: Text("FlutterACPIdentity.urlVariables"),
                  onPressed: () => getUrlVariables(),
                ),
              ]),
            ),
          ],
        ),
      ),
    ));
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_acpcore: ^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_acpcore/flutter_acpcore.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
55
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
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

Health suggestions

Fix lib/src/acpextension_event.dart. (-1 points)

Analysis of lib/src/acpextension_event.dart reported 2 hints:

line 29 col 7: Avoid wrapping fields in getters and setters just to be "safe".

line 32 col 29: Avoid wrapping fields in getters and setters just to be "safe".

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.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