@adobe/react-native-aeptarget
v6.0.2
Published
Adobe Experience Platform support for React Native apps.
Downloads
16,573
Readme
React Native AEP Target Extension
@adobe/react-native-aeptarget
is a wrapper around the iOS and Android AEP Target SDK to allow integration with React Native applications.
Peer Dependencies
The Adobe Experience Platform Target extension has the following peer dependency, which must be installed prior to installing the target extension:
Installation
See Requirements and Installation instructions on the main page
Install the @adobe/react-native-aeptarget
package:
NPM:
npm install @adobe/react-native-aeptarget
Yarn:
yarn add @adobe/react-native-aeptarget
Usage
Initializing and registering the extension
Initialization of the SDK should be done in native code, documentation on how to initialize the SDK can be found here.
Example:
iOS
@import AEPCore;
@import AEPLifecycle;
@import AEPEdge;
@import AEPTarget;
@implementation AppDelegate
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[AEPMobileCore setLogLevel: AEPLogLevelDebug];
[AEPMobileCore configureWithAppId:@"yourAppID"];
const UIApplicationState appState = application.applicationState;
[AEPMobileCore registerExtensions: @[AEPMobileEdge.class, AEPMobileTarget.class] completion:^{
if (appState != UIApplicationStateBackground) {
[AEPMobileCore lifecycleStart:nil];
}
}];
return YES;
}
@end
Android
import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.InvalidInitException;
import com.adobe.marketing.mobile.Lifecycle;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.Target;
...
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");
List<Class<? extends Extension>> extensions = Arrays.asList(
Edge.EXTENSION,
Target.EXTENSION);
MobileCore.registerExtensions(extensions, o -> {
MobileCore.lifecycleStart(null);
});
}
}
Importing the extension:
import {
Target,
TargetOrder,
TargetParameters,
TargetPrefetchObject,
TargetProduct,
TargetRequestObject,
} from "@adobe/react-native-aeptarget";
API Reference
Getting the extension version:
Syntax
extensionVersion(): Promise<string>
Example
const version = await Target.extensionVersion();
console.log("AdobeExperienceSDK: AEPTarget version: " + version);
Get custom visitor IDs:
Syntax
getThirdPartyId(): Promise<string>
Example
const id = await Target.getThirdPartyId();
console.log("AdobeExperienceSDK: Third Party ID: " + id);
Set custom visitor IDs:
Syntax
setThirdPartyId(<id>): void
Example
Target.setThirdPartyId("thirdPartyId");
Reset user experience:
Syntax
resetExperience(): void
Example
Target.resetExperience();
Get Target Session ID:
Syntax
getSessionId(): Promise<string>
Example
const id = await Target.getSessionId();
console.log("AdobeExperienceSDK: Session ID " + id);
Get Target user identifier:
Syntax
getTntId(): Promise<string>
Example
const id = await Target.getTntId();
console.log("AdobeExperienceSDK: TNT ID " + id);
Load Target requests:
Syntax
retrieveLocationContent(Array<TargetRequestObject>, <TargetParameters>): void
Example
var mboxParameters1 = { status: "platinum" };
var mboxParameters2 = { userType: "Paid" };
var purchaseIDs = ["34", "125"];
var targetOrder = new TargetOrder("ADCKKIM", 344.3, purchaseIDs);
var targetProduct = new TargetProduct("24D3412", "Books");
var parameters1 = new TargetParameters(mboxParameters1, null, null, null);
var request1 = new TargetRequestObject(
"mboxName2",
parameters1,
"defaultContent1",
(error, content) => {
if (error) {
console.error(error);
} else {
console.log("Adobe content:" + content);
}
}
);
var parameters2 = new TargetParameters(
mboxParameters1,
{ profileParameters: "parameterValue" },
targetProduct,
targetOrder
);
var request2 = new TargetRequestObject(
"mboxName2",
parameters2,
"defaultContent2",
(error, content) => {
if (error) {
console.error(error);
} else {
console.log("Adobe content:" + content);
}
}
);
var locationRequests = [request1, request2];
var profileParameters1 = { ageGroup: "20-32" };
var parameters = new TargetParameters(
{ parameters: "parametervalue" },
profileParameters1,
targetProduct,
targetOrder
);
Target.retrieveLocationContent(locationRequests, parameters);
Using the prefetch APIs:
Syntax
prefetchContent(Array<TargetPrefetchObject>, <TargetParameters>): Promise<any>
Example
var mboxParameters1 = { status: "platinum" };
var mboxParameters2 = { userType: "Paid" };
var purchaseIDs = ["34", "125"];
var targetOrder = new TargetOrder("ADCKKIM", 344.3, purchaseIDs);
var targetProduct = new TargetProduct("24D3412", "Books");
var parameters1 = new TargetParameters(mboxParameters1, null, null, null);
var prefetch1 = new TargetPrefetchObject("mboxName2", parameters1);
var parameters2 = new TargetParameters(
mboxParameters1,
{ profileParameters: "parameterValue" },
targetProduct,
targetOrder
);
var prefetch2 = new TargetPrefetchObject("mboxName2", parameters2);
var prefetchList = [prefetch1, prefetch2];
var profileParameters1 = { ageGroup: "20-32" };
var parameters = new TargetParameters(
{ parameters: "parametervalue" },
profileParameters1,
targetProduct,
targetOrder
);
Target.prefetchContent(prefetchList, parameters)
.then((success) => console.log(success))
.catch((err) => console.log(err));
Set Session ID
Syntax
Target.setSessionId(<sessionId>): void
Example
Target.setSessionId("sessionId");
Set TNT ID
Syntax
Target.setTntId(<tntId>): void
Example
Target.setTntId("tntId");
Set preview restart deep link:
Syntax
setPreviewRestartDeeplink(<deeplink>): void;
Example
Target.setPreviewRestartDeeplink("https://www.adobe.com");
Send an mbox click notification:
Syntax
clickedLocation(<locationName>, <TargetParameters>): void;
Example
var purchaseIDs = ["34", "125"];
var targetOrder = new TargetOrder("ADCKKIM", 344.3, purchaseIDs);
var targetProduct = new TargetProduct("24D3412", "Books");
var profileParameters1 = { ageGroup: "20-32" };
var parameters = new TargetParameters(
{ parameters: "parametervalue" },
profileParameters1,
targetProduct,
targetOrder
);
Target.clickedLocation("locationName", parameters);
Send an mbox location displayed notification:
Syntax
displayedLocations(Array<string>, <TargetParameters>): void;
Example
var purchaseIDs = ["34", "125"];
var targetOrder = new TargetOrder("ADCKKIM", 344.3, purchaseIDs);
var targetProduct = new TargetProduct("24D3412", "Books");
var profileParameters1 = { ageGroup: "20-32" };
var parameters = new TargetParameters(
{ parameters: "parametervalue" },
profileParameters1,
targetProduct,
targetOrder
);
Target.displayedLocations(["locationName", "locationName1"], parameters);
TargetPrefetchObject:
The Target extension exports a class TargetPrefetchObject
.
constructor(name?: string, targetParameters?: TargetParameters);
TargetRequestObject:
The Target extension exports a class TargetRequestObject
, which extends TargetPrefetchObject
.
constructor(name: string, targetParameters: TargetParameters, defaultContent: string);
TargetOrder:
The Target extension exports a class TargetOrder
.
constructor(orderId: string, total?: number, purchasedProductIds: Array<string>);
TargetProduct:
The Target extension exports a class TargetOrder
.
constructor(productId: string, categoryId: string);
TargetParameters:
The Target extension exports a class TargetParameters
.
constructor(parameters?: Record<string, string>, profileParameters?: Record<string, string>, product?: TargetProduct, order?: TargetOrder);