Adobe Campaign ランディングページからの Adobe Experience Platform プロファイルの更新
- 適用対象:
- Campaign v8 Client Console
- トピック:
- Experience Platform 統合
作成対象:
- 初心者
- 開発者
Adobe Campaign と Adobe Experience Platform の統合により、Adobe Campaign ランディングページと Adobe Experience Platform の間でシームレスにプロファイルデータを同期できます。この統合により、次のことができます。
- Adobe Experience Platform プロファイル属性を取得して、Adobe Campaign ランディングページに更新された情報を表示する
- 更新されたプロファイル属性を Adobe Experience Platform に返し、ランディングページで入力および送信された内容に基づいて、対応する属性を更新する
この統合を設定する主な手順を以下に示します。
OAuth 接続を設定
Adobe Cloud Platform API では、認証と承認に OAuth 2.0 プロトコルを使用します。API 呼び出しを使用して Adobe Experience Platform を Adobe Campaign に接続するには、Adobe Developer Console で作成した OAuth 統合を使用してアクセストークンを生成する必要があります。
これを行うには、次の手順に従います。
-
Adobe Developer Console にアクセスします。
-
Adobe Experience Platform API 製品を使用して、新しい API 接続を作成します。OAuth 2.0 アクセストークンの取得方法に関する詳細な手順については、Adobe Developer Console ドキュメントを参照してください。
-
接続を作成したら、OAuth サーバー間 メニューに移動し、Campaign で認証に必要な以下の詳細をコピーします。
CLIENT ID
CLIENT SECRET
ORGANIZATION ID
Oauth 接続を設定したら、新しい HTTP API ソース接続を作成して設定し、Adobe Campaign を Adobe Experience Platform にリンクします。
HTTP API ソース接続を作成
OAuth 接続を設定したら、次の手順では Adobe Experience Platform で HTTP API ソース接続を作成します。この接続により、API を使用して Adobe Experience Platform にデータをストリーミングできます。次の手順に従います。
-
Adobe Experience Platform ソース に移動し、HTTP API ソースを検索して、「データを追加」をクリックします。
-
必要に応じて、接続を設定します。HTTP API 接続の設定方法について詳しくは、Adobe Experience Platform ソースドキュメントを参照してください。
認証 手順で、「認証を有効にする」オプションの切替スイッチをオンにして、OAuth 統合を通じて事前に生成されたアクセストークンを使用して認証します。
-
ソース接続を設定すると、ストリーミングエンドポイントが表示されます。このエンドポイントは、Adobe Experience Platform にデータを取り込むために必要です。
また、「データフロー」タブから新しく作成したデータフローを開いて、Adobe Experience Platform に取り込まれたデータ形式のサンプルにアクセスすることもできます。
HTTP API ソース接続を設定したら、Adobe Campaign に特定のオプションを追加して、Adobe Experience Platform への接続を有効にする必要があります。
Adobe Campaign で認証オプションを追加
HTTP API ソース接続を設定したら、Adobe Campaign に特定のオプションを追加して、Adobe Experience Platform との接続を有効にする必要があります。これは、Campaign 管理メニューで行うことも、特定の JavaScript コード アクティビティを追加してランディングページワークフローを実行する際に行うこともできます。
以下のタブを参照して、2 つの方法を確認します。
-
管理/プラットフォーム/オプション メニューに移動します。
-
Adobe Developer Console から、次のオプションと対応する値を追加します。
- IMS_CLIENT_ID = cryptString(CLIENT ID)
- IMS_CLIENT_SECRET = cryptString(CLIENT SECRET)
- IMS_ORG_ID = ORGANIZATION ID
- IMS_CLIENT_API_KEY = cryptString(CLIENT ID)
NOTE
cryptString() 関数は、認証データを暗号化するために使用します。
ランディングページワークフローの実行時にこれらのオプションを自動的に設定するには、以下のコードを使用して、JavaScript コード アクティビティをワークフローに追加します。詳しくは、JavaScript コードアクティビティの設定方法を参照してください。
ワークフローの実行時に、指定された値を使用してオプションが Campaign コンソールに自動的に作成されます。
loadLibrary("xtk:shared/nl.js");
loadLibrary("xtk:shared/xtk.js");
loadLibrary("xtk:shared/json2.js");
loadLibrary("xtk:common.js");
function setAuthCredentials()
{
setOption("IMS_CLIENT_ID", cryptString('CLIENT ID'));
setOption("IMS_CLIENT_SECRET", cryptString('CLIENT SECRET'));
setOption("IMS_ORG_ID", cryptString('ORGANIZATION ID'));
setOption("IMS_CLIENT_API_KEY", cryptString('CLIENT ID'));
}
認証オプションを Campaign に設定したら、ランディングページから Campaign と Adobe Experience Platform の間でデータを同期できるようにするカスタム JavaScript コードを作成する必要があります。
ワークフロー実行時のオプションを追加
ランディングページと Adobe Experience Platform の間でデータを同期できるようにするには、カスタム JavaScript コードを Adobe Campaign に追加する必要があります。次の手順に従います。
-
管理/設定/JavaScript コード メニューに移動します。
-
新しい JavaScript コードを作成し、以下のスニペットをコピー&ペーストします。
NOTE
アクセストークンと認証データは、以前に設定したオプションから自動的に取得されます。
このコードでは、ランディングページを読み込む前に、Adobe Experience Platform にプロファイルが存在するかどうかを確認します。プロファイル属性を取得し、ランディングページの対応するフィールドに表示します。
// API implementation to read profile from AEP
function getProfileInfo(email)
{
var accessToken = getAccessToken();
var request = new HttpClientRequest(('https://platform-stage.adobe.io/data/core/ups/access/entities?schema.name=_xdm.context.profile&entityId=' + email + '&entityIdNS=email&fields=identities,consents.marketing'));
request.method = 'GET';
request.header["Content-Type"] = "application/json";
request.header["sandbox-name"] = "prod";
request.header["x-gw-ims-org-id"] = getOption('IMS_ORG_ID');
request.header["x-api-key"] = getOption('IMS_CLIENT_API_KEY');
request.header["Authorization"] = "Bearer " + accessToken;
request.execute();
return request.response;
}
このコードでは、ランディングページで送信した値で Adobe Experience Platform のプロファイル属性を更新します。
// API implementation to update profile in AEP
loadLibrary("xtk:shared/nl.js");
loadLibrary("xtk:shared/xtk.js");
loadLibrary("xtk:shared/json2.js");
loadLibrary("xtk:common.js");
function updateProfileInAEP(profileUpdatePayload)
{
var accessToken = getAccessToken();
var request = new HttpClientRequest('https://dcs-stg.adobedc.net/collection/64a300b84d61c0bcea4f0cd4ecaaa224a19477026d14f7e08b5408ffaf5e6162?syncValidation=false');
request.method = 'POST';
request.header["Content-Type"] = "application/json";
request.header["sandbox-name"] = "prod";
request.header["Authorization"] = "Bearer " + accessToken;
var body = '{"header":{"schemaRef":{"id":"https://ns.adobe.com/campdev/schemas/35d8e567772e1a1093ed6cf9e41d2c1fec22eeb3a89583e1","contentType":"application/vnd.adobe.xed-full+json;version=1.0"},"imsOrgId":"A1F66F0D5C47D1950A494133@AdobeOrg","datasetId":"63c7fa2a20cce11b98cccb41","source":{"name":"testHTTPSourcesVinay - 03/06/2023 5:43 PM"}},"body":{"xdmMeta":{"schemaRef":{"id":"https://ns.adobe.com/campdev/schemas/35d8e567772e1a1093ed6cf9e41d2c1fec22eeb3a89583e1","contentType":"application/vnd.adobe.xed-full+json;version=1.0"}},"xdmEntity":' + profileUpdatePayload +'}}';
request.body = body;
request.execute();
return request.response;
}
// Get Access token from OAuth-Server-to-server API call
function getAccessToken() {
var clientId = decryptString(getOption('IMS_CLIENT_ID'));
var clientSecret = decryptString(getOption('IMS_CLIENT_SECRET'));
var request = new HttpClientRequest(('https://ims-na1-stg1.adobelogin.com/ims/token/v2?grant_type=client_credentials' + '&client_id=' + clientId + '&client_secret=' + clientSecret + '&scope=openid,session,AdobeID,read_organizations,additional_info.projectedProductContext'));
request.method = 'POST';
request.execute();
var response = request.response;
if(response.code != 200){
logError('GetAccessToken failed,', response.code, response.body);
return;
}
var body = ''+response.body;
var parsedResponse = JSON.parse(body);
var accessToken = parsedResponse.access_token;
logInfo("Access token generated successfully");
return accessToken;
}
カスタム JavaScript コードを Adobe Campaign に作成したので、データ同期にこれらの JavaScript コードを使用するようにランディングページを含むワークフローを設定できます。
ランディングページワークフローを設定
Adobe Campaign に追加した JavaScript コードを、JavaScript コード アクティビティを使用してランディングページのワークフローに活用できます。
- ランディングページを読み込む前に Experience Platform からデータを読み込むには、ランディングページアクティビティの前に JavaScript コード アクティビティを追加し、スクリプト 1 をコピー&ペーストします。
// Script code to read profile from AEP.
logInfo("Loading profile from AEP");
loadLibrary("cus:aepAPI");
var recipient=ctx.recipient;
var email = recipient.@email;
var response = getProfileInfo(email);
ctx.isAEPProfileExists = 1;
if(response.code == 404){
ctx.isAEPProfileExists = 0
logInfo("Profile with email" + email + " not found in AEP, ignoring the update activity");
}
else if(response.code == 200){
var body = ''+response.body;
var parsedResponse = JSON.parse(body);
for (var key in parsedResponse) {
var value = parsedResponse[key];
var marketing = value.entity.consents.marketing;
logInfo("User Consent Details: " + JSON.stringify(marketing));
if(marketing.hasOwnProperty('email')&&marketing.email.hasOwnProperty('val')&&marketing.email.val=='n'){
ctx.recipient.@blackListEmail = 1;
}
if(marketing.hasOwnProperty('sms')&&marketing.sms.hasOwnProperty('val')&&marketing.sms.val=='n'){
ctx.recipient.@blackListMobile = 1;
}
if(marketing.hasOwnProperty('push')&&marketing.push.hasOwnProperty('val')&&marketing.push.val=='n'){
ctx.recipient.@blackListPostalMail = 1;
}
}
}
- ランディングページで送信したデータで Experience Platform プロファイル属性を更新するには、ランディングページアクティビティの後に JavaScript コード アクティビティを追加し、スクリプト 2 をコピー&ペーストします。
// Script code to update profile in AEP and ACC.
logInfo("Executing script to update AEP profile.");
// Loading aepAPI library JS code
loadLibrary("cus:aepAPI");
var recipient=ctx.recipient
// Update profile only if it exists in AEP
if(ctx.isAEPProfileExists==1){
var email = recipient.@email
logInfo(email);
logInfo(recipient.@blackListEmail);
logInfo(recipient.@blackListMobile);
logInfo(recipient.@blackListPostalMail);
var optOutPayload = new Array();
if(recipient.@blackListEmail==1){
optOutPayload.push('"email":{"val":"n"}');
}
else
optOutPayload.push('"email":{"val":"y"}');
if(recipient.@blackListMobile==1){
optOutPayload.push('"sms":{"val":"n"}');
}
else
optOutPayload.push('"sms":{"val":"y"}');
if(recipient.@blackListPostalMail==1){
optOutPayload.push('"push":{"val":"n"}');
}
else
optOutPayload.push('"push":{"val":"y"}');
var profileUpdatePayload = '{'+ '"personalEmail":{"address":' + '\"' + email + '\"' + '},' +'"consents":{"marketing":{' + optOutPayload.toString() + '}}}';
var response = updateProfileInAEP(profileUpdatePayload);
if(response.code == 200){
var body = '' + response.body;
logInfo("AEP Profile Updated successfully, Response " + body);
// Update ACC profile
recipient.@xtkschema = "nms:recipient";
recipient.@_operation = "update";
recipient.@_key="@id";
xtk.session.Write(recipient);
logInfo("ACC Profile Updated successfully");
}
else{
logError('Server Error: ', response.code, response.body);
}
}
else {
logInfo("Ignoring AEP profile update as profile doesn't exists.");
// Update ACC profile
recipient.@xtkschema = "nms:recipient";
recipient.@_operation = "update";
recipient.@_key="@id";
xtk.session.Write(recipient);
logInfo("ACC Profile Updated successfully");
}
ランディングページの前後で JavaScript コードアクティビティを使用するサンプルワークフローを以下に示します。
Adobe Experience Platform でプロファイル属性を更新するように設定したランディングページと JavaScript コードアクティビティの例を以下に示します。