@adobe/react-native-aeptarget
is a wrapper around the iOS and Android AEP Target SDK to allow integration with React Native applications.
The Adobe Experience Platform Target extension has the following peer dependency, which must be installed prior to installing the target extension:
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
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: AEPLogLevelTrace];
[AEPMobileCore registerExtensions: @[AEPMobileEdge.class, AEPMobileTarget.class] completion:^{
[AEPMobileCore configureWithAppId:@"yourAppID"];
[AEPMobileCore lifecycleStart:@{@"contextDataKey": @"contextDataVal"}];
}
];
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);
try {
Edge.registerExtension();
Target.registerExtension();
MobileCore.configureWithAppID("yourAppID");
MobileCore.start(new AdobeCallback() {
@Override
public void call(Object o) {
MobileCore.lifecycleStart(null);
}
});
} catch (InvalidInitException e) {
...
}
}
}
import {
Target,
TargetOrder,
TargetParameters,
TargetPrefetchObject,
TargetProduct,
TargetRequestObject
} from '@adobe/react-native-aeptarget';
Syntax
extensionVersion(): Promise<string>
Example
const version = await Target.extensionVersion();
console.log('AdobeExperienceSDK: AEPTarget version: ' + version);
Syntax
getThirdPartyId(): Promise<string>
Example
const id = await Target.getThirdPartyId();
console.log('AdobeExperienceSDK: Third Party ID: ' + id);
Syntax
setThirdPartyId(<id>): void
Example
Target.setThirdPartyId('thirdPartyId');
Syntax
resetExperience(): void
Example
Target.resetExperience();
Syntax
getSessionId(): Promise<string>
Example
const id = await Target.getSessionId();
console.log('AdobeExperienceSDK: Session ID ' + id);
Syntax
getTntId(): Promise<string>
Example
const id = await Target.getTntId();
console.log('AdobeExperienceSDK: TNT ID ' + id);
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);
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));
Syntax
Target.setSessionId(<sessionId>): void
Example
Target.setSessionId('sessionId');
Syntax
Target.setTntId(<tntId>): void
Example
Target.setTntId('tntId');
Syntax
setPreviewRestartDeeplink(<deeplink>): void;
Example
Target.setPreviewRestartDeeplink('https://www.adobe.com');
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);
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);
The Target extension exports a class TargetPrefetchObject
.
constructor(name?: string, targetParameters?: TargetParameters);
The Target extension exports a class TargetRequestObject
, which extends TargetPrefetchObject
.
constructor(name: string, targetParameters: TargetParameters, defaultContent: string);
The Target extension exports a class TargetOrder
.
constructor(orderId: string, total?: number, purchasedProductIds: Array<string>);
The Target extension exports a class TargetOrder
.
constructor(productId: string, categoryId: string);
The Target extension exports a class TargetParameters
.
constructor(parameters?: Record<string, string>, profileParameters?: Record<string, string>, product?: TargetProduct, order?: TargetOrder);