Flutter桥接插件flutter_aepedgebridge的使用

Flutter桥接插件flutter_aepedgebridge的使用

flutter_aepedgebridge 是一个为iOS和Android平台设计的Flutter插件,用于与Adobe Experience Platform Edge Bridge进行集成。该插件允许现有的SDK实现无缝地将数据路由到Adobe Experience Platform Edge网络。

简介

pub package Build License

flutter_aepedgebridge

Edge Bridge移动扩展为现有SDK实现提供了无缝的数据路由到Adobe Experience Platform Edge网络。对于已经使用了MobileCore.trackAction和/或MobileCore.trackState API向Adobe Analytics发送数据的应用程序,此扩展会自动将这些API调用路由到Edge网络,使得数据可用于通过Data Prep for Data Collection映射到用户的XDM模式。

重要提示

Edge Bridge主要作为已经在其实现中使用Adobe Analytics的应用程序的迁移辅助工具。

对于新开发的应用程序,强烈建议使用Edge Network扩展的Edge.sendEvent API。

前置条件

Edge Bridge扩展有以下依赖项,在安装Edge Bridge扩展之前必须先安装:

  • flutter_aepcore
  • flutter_aepedge
  • flutter_aepedgeidentity

安装

安装说明可以在这里找到。

注意:在安装SDK后,别忘了在你的ios目录中运行pod install来将库链接到你的Xcode项目。

测试

运行:

flutter test

使用方法

安装并注册扩展与AEP Mobile Core

在你的移动属性中安装Adobe Experience Platform Edge Network扩展,并通过遵循Edge Network扩展文档中的步骤配置默认Datastream ID。

注意:Experience Platform Edge Bridge在数据收集UI中没有对应的扩展卡片;无需更改数据收集移动属性即可使用Edge Bridge。

在AEPCore中注册扩展

注意:必须通过本机代码(iOS中的AppDelegate,Android中的MainApplication类)初始化SDK。

在初始化代码中,确保在启动SDK之前设置SDK包装类型为Flutter

有关初始化SDK的更多信息,请参阅根README中的初始化部分。

初始化示例

iOS

// AppDelegate.h
@import AEPCore;
@import AEPEdge;
@import AEPEdgeIdentity;
@import AEPEdgeBridge;
...
@implementation AppDelegate

// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [AEPMobileCore setWrapperType:AEPWrapperTypeFlutter];

     // TODO: 设置从你的移动属性中配置的数据收集UI中的首选环境文件ID
    NSString* ENVIRONMENT_FILE_ID = @"YOUR-APP-ID";
    
    NSArray *extensionsToRegister = @[AEPMobileEdgeIdentity.class, 
                                      AEPMobileEdge.class,                                              
                                      AEPMobileEdgeBridge.class
                                      ];

    [AEPMobileCore registerExtensions:extensionsToRegister completion:^{
      [AEPMobileCore configureWithAppId: ENVIRONMENT_FILE_ID];
    }];
    return YES;   
 } 

Android

import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.edge.identity.Identity;
import com.adobe.marketing.mobile.edge.bridge.EdgeBridge;

...
import io.flutter.app.FlutterApplication;
...

public class MainApplication extends FlutterApplication {
  ...

  // TODO: 设置从你的移动属性中配置的数据收集UI中的首选环境文件ID
  private final String ENVIRONMENT_FILE_ID = "YOUR-APP-ID";

  @Override
  public void onCreate() {
    super.onCreate();
    ...
    MobileCore.setApplication(this);
    MobileCore.setWrapperType(WrapperType.FLUTTER);
    MobileCore.configureWithAppID(ENVIRONMENT_FILE_ID);

    MobileCore.registerExtensions(
      Arrays.asList(Identity.EXTENSION, Edge.EXTENSION, EdgeBridge.EXTENSION),
      o -> Log.d("MainApp", "Adobe Experience Platform Mobile SDK was initialized")
    );
  }
}

导入SDK

import 'package:flutter_aepedgebridge/flutter_aepedgebridge.dart';

Edge Bridge教程

有关实现Edge Bridge和Data Prep映射的教程,请参阅Edge Bridge教程

验证

通过Edge工作流验证Edge Bridge事件,可以使用Assurance中的Event Transactions视图或Analytics Events 2.0视图。

API参考

extensionVersion

返回客户端侧Edge Bridge扩展的版本。

语法

static Future<String> get extensionVersion

示例

String version = await EdgeBridge.extensionVersion;

更多关于Flutter桥接插件flutter_aepedgebridge的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter桥接插件flutter_aepedgebridge的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


在Flutter项目中,使用flutter_aepedgebridge插件可以实现与Adobe Experience Platform Edge Network(AEP Edge Network)的桥接。这通常用于在Flutter应用中集成Adobe Analytics、Adobe Target等功能。以下是一个简单的代码案例,展示了如何在Flutter项目中设置和使用flutter_aepedgebridge插件。

1. 添加依赖

首先,在pubspec.yaml文件中添加flutter_aepedgebridge依赖:

dependencies:
  flutter:
    sdk: flutter
  flutter_aepedgebridge: ^最新版本号  # 替换为实际的最新版本号

然后运行flutter pub get来获取依赖。

2. 配置插件

在Flutter应用的入口文件(通常是main.dart)中,进行必要的配置。

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

void main() {
  // 初始化插件
  EdgeNetwork.instance.initialize(
    configId: 'YOUR_CONFIG_ID',  // 替换为你的配置ID
    orgId: 'YOUR_ORG_ID',        // 替换为你的组织ID
  );

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter AEP Edge Bridge Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter AEP Edge Bridge Demo'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            // 发送事件到AEP Edge Network
            sendEvent();
          },
          child: Text('Send Event'),
        ),
      ),
    );
  }

  Future<void> sendEvent() async {
    try {
      // 构建事件数据
      Map<String, dynamic> eventData = {
        'eventType': 'custom.event',
        'eventDetails': {
          'key1': 'value1',
          'key2': 'value2',
        },
      };

      // 发送事件
      await EdgeNetwork.instance.sendEvent(eventData);
      print('Event sent successfully');
    } catch (e) {
      print('Failed to send event: $e');
    }
  }
}

3. 权限和网络配置

确保你的应用具有必要的网络权限。对于Android,你可能需要在AndroidManifest.xml中添加网络权限:

<uses-permission android:name="android.permission.INTERNET" />

对于iOS,你可能需要在Info.plist中添加必要的网络配置,比如允许应用访问特定的域。

4. 运行应用

完成上述步骤后,你可以运行Flutter应用,点击按钮发送事件到AEP Edge Network。

注意事项

  • 确保你已经正确设置了Adobe Experience Platform Edge Network的配置ID和组织ID。
  • 根据你的具体需求,调整事件数据的结构和内容。
  • 查阅flutter_aepedgebridge的官方文档以获取更多高级用法和配置选项。

这个代码案例展示了如何在Flutter应用中初始化flutter_aepedgebridge插件并发送事件。根据你的实际需求,你可能需要进一步定制和扩展这个示例。

回到顶部