@adobe/react-native-aepedgeidentity 中文文档教程

发布于 3年前 浏览 1 项目主页 更新于 3年前

React Native Adobe Experience Platform Identity for Edge Network Extension

npm 版本npm downloads

@adobe/react-native-aepedgeidentity 是 iOS 和 Android Adobe Experience Platform Identity for Edge Network Extension 以允许与 React Native 应用程序集成。

Prerequisites

Adobe Experience Platform Identity for Edge Network 扩展具有以下对等依赖项,必须在安装身份扩展之前安装:

Installation

请参阅 要求和安装说明

安装@adobe/react-native-aepedgeidentity包:

cd MyReactApp
npm install @adobe/react-native-aepedgeidentity

Usage

Installing and registering the extension with the AEP Mobile Core

边缘网络的身份需要在以下情况下向边缘网络扩展提供身份信息发送体验事件。

按照 Identity for Edge Network 中的步骤在您的移动资产中安装身份扩展扩展文档

然后按照相同的文档向 Mobile Core 注册身份扩展。 请注意,初始化 SDK 应以本机代码完成,有关如何初始化 SDK 的其他文档可在此处。

初始化示例

iOS

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

// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [AEPMobileCore setLogLevel: AEPLogLevelDebug];
    [AEPMobileCore registerExtensions:@[AEPMobileEdgeIdentity.class, 
                                        AEPMobileEdge.class] completion:^{
      [AEPMobileCore configureWithAppId:@"yourAppID"];  
    ...   
   }]; 
   return YES;   
 } 

@end

Android

import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.edge.identity.Identity;  
...
import android.app.Application;
...
public class MainApplication extends Application implements ReactApplication {
  ...
  @Override
  public void on Create(){
    super.onCreate();
    ...
    MobileCore.setApplication(this);
    MobileCore.setLogLevel(LoggingMode.DEBUG);
    MobileCore.configureWithAppID("yourAppID");

    Edge.registerExtension();
    Identity.registerExtension();
    MobileCore.start(new AdobeCallback() {
        @Override
        public void call(Object o) {

    }});
  }
}     

:information_source:如果您的用例涵盖边缘网络和 Adob​​e Experience Cloud 解决方案扩展,您需要为边缘网络注册身份,并为 Experience Cloud 身份服务扩展注册移动核心身份。 有关详细信息,请参阅 常见问题

Identity for Edge Network

Importing the extension:

在您的 React Native 应用程序中,按如下方式导入身份扩展:

import {Identity} from '@adobe/react-native-aepedgeidentity';

API reference

extensionVersion:

返回边缘网络扩展身份的版本

语法

extensionVersion(): Promise<string>;

示例

Identity.extensionVersion().then(version => console.log("AdobeExperienceSDK: EdgeIdentity version: " + version));

getExperienceCloudId:

此 API 检索应用程序生成的 ECID最初推出。 此 ID 在应用程序升级之间保留,在标准应用程序备份过程中保存和恢复,并在卸载时删除。 一旦 Experience Cloud ID 可用或发生意外错误或请求超时时将被拒绝的承诺方法。

语法

getExperienceCloudId(): Promise<string>;

示例

Identity.getExperienceCloudId().then(experienceCloudId => console.log("AdobeExperienceSDK: Experience Cloud Id = " + experienceCloudId));

getIdentities:

获取 Identity for Edge Network 扩展中的所有身份,包括之前添加的客户标识符。 一个 promise 方法,一旦身份可用或在发生意外错误或请求超时时将被拒绝。

语法

getIdentities(): Promise<IdentityMap>;

示例

Identity.getIdentities().then(identities => console.log("AdobeExperienceSDK: Get Identities = " + JSON.stringify(identities)));

removeIdentity:

从存储的客户端IdentityMap 中删除身份。 身份扩展将停止向边缘网络发送标识符。 使用此 API 不会从服务器端用户配置文件图或身份图中删除标识符。

不允许使用具有空 ID 或命名空间的身份,这些身份将被忽略。

使用此 API 不允许使用保留命名空间删除身份。 保留的命名空间是:

  • ECID
  • IDFA
  • GAID

Syntax

removeIdentity(item: IdentityItem, namespace: string);

Example

let identityItem  = new IdentityItem("user@example.com");
Identity.removeIdentity(identityItem, "Email");

resetIdentity:

清除存储在身份扩展中的所有身份并生成新的 Experience Cloud ID (ECID)。 使用此 API 不会从服务器端用户配置文件图或身份图中删除标识符。

:information_source: 边缘网络身份扩展不会读取移动 SDK 的隐私状态,因此将 SDK 的隐私状态设置为选择退出不会清除边缘网络身份扩展中的身份。

有关详细信息,请参阅MobileCore.resetIdentities API

updateIdentities:

更新 SDK 中当前已知的身份。 Identity 扩展会将接收到的标识符与先前保存的标识符以附加方式合并,不会从该 API 中删除任何身份。

不允许使用具有空 ID 或命名空间的身份,这些身份将被忽略。

使用此 API 不允许使用保留命名空间更新身份。 保留的命名空间是:

  • ECID
  • IDFA
  • GAID

语法

updateIdentities(identityMap: IdentityMap);

示例

let identityItem  = new IdentityItem("user@example.com");
let map = new IdentityMap();
map.addItem(identityItem, "Email");
Identity.updateIdentities(map);

Public Classes

IdentityMap

定义包含一组最终用户身份的映射,以命名空间集成代码或身份的命名空间 ID 为关键字。 映射的值是一个数组,这意味着每个名称空间可以携带多个标识。 IdentityMap 类的格式由 XDM Identity Map Schema 定义

有关详细信息,请阅读 AEP 身份服务 的概述。

"identityMap" : {
    "Email" : [
      {
        "id" : "user@example.com",
        "authenticatedState" : "authenticated",
        "primary" : false
      }
    ],
    "Phone" : [
      {
        "id" : "1234567890",
        "authenticatedState" : "ambiguous",
        "primary" : false
      },
      {
        "id" : "5557891234",
        "authenticatedState" : "ambiguous",
        "primary" : false
      }
    ],
    "ECID" : [
      {
        "id" : "44809014977647551167356491107014304096",
        "authenticatedState" : "ambiguous",
        "primary" : true
      }
    ]
  }

Example

let map = new IdentityMap();

// Add an item
let identityItem  = new IdentityItem("user@example.com");
map.addItem(identityItem, "Email");

// Remove an item
let identityItem  = new IdentityItem("user@example.com");
map.removeItem(identityItem, "Email");

//Get a list of items for a given namespace
let namespacecheck = map.getIdentityItemsForNamespace("Email");

//Get a list of all namespaces used in current IdentityMap
let namespaces = map.getNamespaces();

//Check if IdentityMap has no identities
let hasNoIdentities = map.isEmpty();

IdentityItem

定义要包含在 IdentityMap 中的身份。

IdentityItem 类的格式由 XDM Identity Item Schema 定义。

示例

// Initialize
let item  = new IdentityItem("identifier");

let item  = new IdentityItem("identifier", AuthenticatedState.AUTHENTICATED, false);

//Getters
let id = item.id;
let state = item.authenticatedState;
let primary = item.primary

AuthenticatedState

定义Identity Item 的身份验证状态。

可能的身份验证状态是:

  • Ambiguous - the state is ambiguous or not defined
  • Authenticated - the user is identified by a login or similar action
  • LoggedOut - the user was identified by a login action at a previous time, but is not logged in now

Syntax

 static AUTHENTICATED: string;
 static LOGGED_OUT: string;
 static AMBIGUOUS: string;

Frequently Asked Questions (FAQ)

有关更多详细信息,请参阅network/identity-faq">常见问题页面

React Native Adobe Experience Platform Identity for Edge Network Extension

npm versionnpm downloads

@adobe/react-native-aepedgeidentity is a wrapper around the iOS and Android Adobe Experience Platform Identity for Edge Network Extension to allow for integration with React Native applications.

Prerequisites

The Adobe Experience Platform Identity for Edge Network extension has the following peer dependency, which must be installed prior to installing the identity extension:

Installation

See Requirements and Installation instructions on the main page

Install the @adobe/react-native-aepedgeidentity package:

cd MyReactApp
npm install @adobe/react-native-aepedgeidentity

Usage

Installing and registering the extension with the AEP Mobile Core

The Identity for Edge Network is required for providing the identity information to the Edge Network extension when sending Experience events.

Install the Identity extension in your mobile property by following the steps in the Identity for Edge Network extension documentation.

Then follow the same document for registering the Identity extension with the Mobile Core. Note that initializing the SDK should be done in native code, additional documentation on how to initialize the SDK can be found here.

Initialization Example

iOS

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

// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [AEPMobileCore setLogLevel: AEPLogLevelDebug];
    [AEPMobileCore registerExtensions:@[AEPMobileEdgeIdentity.class, 
                                        AEPMobileEdge.class] completion:^{
      [AEPMobileCore configureWithAppId:@"yourAppID"];  
    ...   
   }]; 
   return YES;   
 } 

@end

Android

import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.edge.identity.Identity;  
...
import android.app.Application;
...
public class MainApplication extends Application implements ReactApplication {
  ...
  @Override
  public void on Create(){
    super.onCreate();
    ...
    MobileCore.setApplication(this);
    MobileCore.setLogLevel(LoggingMode.DEBUG);
    MobileCore.configureWithAppID("yourAppID");

    Edge.registerExtension();
    Identity.registerExtension();
    MobileCore.start(new AdobeCallback() {
        @Override
        public void call(Object o) {

    }});
  }
}     

:information_source: If your use-case covers both Edge Network and Adobe Experience Cloud Solutions extensions, you need to register Identity for Edge Network and Identity from Mobile Core for Experience Cloud Identity Service extensions. For more details, see the Frequently asked questions.

Identity for Edge Network

Importing the extension:

In your React Native application, import the Identity extension as follows:

import {Identity} from '@adobe/react-native-aepedgeidentity';

API reference

extensionVersion:

Returns the version of the Identity for Edge Network extension

Syntax

extensionVersion(): Promise<string>;

Example

Identity.extensionVersion().then(version => console.log("AdobeExperienceSDK: EdgeIdentity version: " + version));

getExperienceCloudId:

This API retrieves the ECID that was generated when the app was initially launched. This ID is preserved between app upgrades, is saved and restored during the standard application backup process, and is removed at uninstall. A promise method which will be invoked once the Experience Cloud ID is available or rejected if an unexpected error occurred or the request timed out.

Syntax

getExperienceCloudId(): Promise<string>;

Example

Identity.getExperienceCloudId().then(experienceCloudId => console.log("AdobeExperienceSDK: Experience Cloud Id = " + experienceCloudId));

getIdentities:

Get all the identities in the Identity for Edge Network extension, including customer identifiers which were previously added. A promise method which will be invoked once the identities are available or rejected if an unexpected error occurred or the request timed out.

Syntax

getIdentities(): Promise<IdentityMap>;

Example

Identity.getIdentities().then(identities => console.log("AdobeExperienceSDK: Get Identities = " + JSON.stringify(identities)));

removeIdentity:

Remove the identity from the stored client-side IdentityMap. The Identity extension will stop sending the identifier to the Edge Network. Using this API does not remove the identifier from the server-side User Profile Graph or Identity Graph.

Identities with an empty id or namespace are not allowed and are ignored.

Removing identities using a reserved namespace is not allowed using this API. The reserved namespaces are:

  • ECID
  • IDFA
  • GAID

Syntax

removeIdentity(item: IdentityItem, namespace: string);

Example

let identityItem  = new IdentityItem("user@example.com");
Identity.removeIdentity(identityItem, "Email");

resetIdentity:

Clears all identities stored in the Identity extension and generates a new Experience Cloud ID (ECID) . Using this API does not remove the identifiers from the server-side User Profile Graph or Identity Graph.

:information_source: The Identity for Edge Network extension does not read the Mobile SDK's privacy status and therefor setting the SDK's privacy status to opt-out will not clear the identities from the Identity for Edge Network extension.

For more details, see theMobileCore.resetIdentities API.

updateIdentities:

Update the currently known identities within the SDK. The Identity extension will merge the received identifiers with the previously saved ones in an additive manner, no identities are removed from this API.

Identities with an empty id or namespace are not allowed and are ignored.

Updating identities using a reserved namespace is not allowed using this API. The reserved namespaces are:

  • ECID
  • IDFA
  • GAID

Syntax

updateIdentities(identityMap: IdentityMap);

Example

let identityItem  = new IdentityItem("user@example.com");
let map = new IdentityMap();
map.addItem(identityItem, "Email");
Identity.updateIdentities(map);

Public Classes

IdentityMap

Defines a map containing a set of end user identities, keyed on either namespace integration code or the namespace ID of the identity. The values of the map are an array, meaning that more than one identity of each namespace may be carried. The format of the IdentityMap class is defined by the XDM Identity Map Schema.

For more information, please read an overview of the AEP Identity Service.

"identityMap" : {
    "Email" : [
      {
        "id" : "user@example.com",
        "authenticatedState" : "authenticated",
        "primary" : false
      }
    ],
    "Phone" : [
      {
        "id" : "1234567890",
        "authenticatedState" : "ambiguous",
        "primary" : false
      },
      {
        "id" : "5557891234",
        "authenticatedState" : "ambiguous",
        "primary" : false
      }
    ],
    "ECID" : [
      {
        "id" : "44809014977647551167356491107014304096",
        "authenticatedState" : "ambiguous",
        "primary" : true
      }
    ]
  }

Example

let map = new IdentityMap();

// Add an item
let identityItem  = new IdentityItem("user@example.com");
map.addItem(identityItem, "Email");

// Remove an item
let identityItem  = new IdentityItem("user@example.com");
map.removeItem(identityItem, "Email");

//Get a list of items for a given namespace
let namespacecheck = map.getIdentityItemsForNamespace("Email");

//Get a list of all namespaces used in current IdentityMap
let namespaces = map.getNamespaces();

//Check if IdentityMap has no identities
let hasNoIdentities = map.isEmpty();

IdentityItem

Defines an identity to be included in an IdentityMap.

The format of the IdentityItem class is defined by the XDM Identity Item Schema.

Example

// Initialize
let item  = new IdentityItem("identifier");

let item  = new IdentityItem("identifier", AuthenticatedState.AUTHENTICATED, false);

//Getters
let id = item.id;
let state = item.authenticatedState;
let primary = item.primary

AuthenticatedState

Defines the state an Identity Item is authenticated for.

The possible authenticated states are:

  • Ambiguous - the state is ambiguous or not defined
  • Authenticated - the user is identified by a login or similar action
  • LoggedOut - the user was identified by a login action at a previous time, but is not logged in now

Syntax

 static AUTHENTICATED: string;
 static LOGGED_OUT: string;
 static AMBIGUOUS: string;

Frequently Asked Questions (FAQ)

For more details, refer to the frequently asked questions page

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文