iFrames での AppMeasurement の使用
AppMeasurement 変数は、子 iframe と親 iframe の両方から参照できます。 AppMeasurement ライブラリが存在する場所と同じ場所にすべての変数を定義する必要があります。 次の例では、iframe の内外に基本的な AppMeasurement 変数およびメソッドを設定する方法を説明します。
Adobe Experience Platform でタグを使用する場合は、トラッカー オブジェクトがグローバルにアクセス可能であることを確認します。 Adobe Analytics 拡張機能の概要を参照してください。
CAUTION
親ページと iframe の両方に AppMeasurement ライブラリを含めないでください。 これをおこなうと、複数のイメージリクエストが送信される、レポートが水増しされる、課金対象のサーバーコールが増加するなどのリスクが生じます。
iframe 内にある AppMeasurement へのアクセス
iframe オブジェクトを介して AppMeasurement 変数にアクセスできます。 これらの例では、pageName を設定し、2 つの異なる方法を使用して t() メソッドを呼び出して iframe オブジェクトを参照します。
// Reference AppMeasurement code that resides within an iframe and send an image request
document.getElementById('targetFrame').contentWindow.s.pageName="Page name within iframe";
document.getElementById('targetFrame').contentWindow.s.t();
// An alternate method to the above if there's only one iframe on the page
window.frames[0].contentWindow.s.pageName = "Page name within iframe";
window.frames[0].contentWindow.s.t();
iframe 内から AppMeasurement にアクセスする
iframe 内から親ページの AppMeasurement 変数にアクセスできます。 次の使用例は、pageName を設定し、parentプロパティを使用して t()メソッドを呼び出しています。
// Reference AppMeasurement code on a parent page from within an iframe and send an image request
parent.s.pageName = "Page Name on Hosted Window";
parent.s.t();
postMessage とイベントリスナーを使用する
または、postMessage とイベントリスナーを使用して変数を設定できます。 このメソッドでは、iframe に対する直接参照は必要ありません。
// Place this code in your parent window
function listenMessage(e) {
if(e.data == "Example page view call") {
s.pageName = "Page name using postMessage";
s.t();
}
}
window.addEventListener("message", listenMessage, false);
// Place this code in the iframe
window.top.postMessage("Example page view call","https://example.com");
制限事項
- 他の JavaScript コードと同様、iframe はドメインとプロトコルが一致する場合にのみ通信できます。 これらの例は、iframe コンテンツが親とは異なるドメインに存在する場合は機能しません。
- AppMeasurement が iframe 内に存在する場合、
referrer変数は、実際の参照 URL ではなく親 URL に設定されます。referrer変数を手動で設定すると、この問題を解決できます。 - Adobe Experience Platform Debuggerは、iframe内でトリガーされた画像リクエストを認識しません。
- Activity Map には、iframe 内でクリックされたリンクのヒートマップは表示されません。 代わりに、iframe 全体がハイライト表示されます。
recommendation-more-help
analytics-help-implement