AppMeasurement変数は、子iframeと親iframeの両方から参照できます。 AppMeasurementライブラリが存在する場所と同じ場所にすべての変数を定義する必要があります。 次の例では、iframeの内外に基本的なAppMeasurement変数およびメソッドを設定する方法を説明します。
Adobe Experience Platform Launchを使用する場合は、トラッカーオブジェクトがグローバルにアクセスできることを確認します。 LaunchユーザーガイドのAdobe Analytics拡張機能の概要を参照してください。
!![CAUTION]
親ページとiframeの両方にAppMeasurementライブラリを含めないでください。 これにより、複数のイメージリクエストを送信し、レポートを水増しし、課金対象のサーバーコールを増やすリスクが生じます。
AppMeasurement変数は、iframeオブジェクトを介してアクセスできます。 次の例では、iframeオブジェクトを参照する2つの異なる方法を使用して、pageNameを設定し、t()メソッドを呼び出します。
// 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();
親ページ上のAppMeasurement変数には、iframe内からアクセスできます。 次の使用例は、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");
referrer
変数は、実際の参照URLではなく親URLに設定されます。 referrer
変数を手動で設定すると、この問題を解決できます。