當使用者採取某些行動 (例如點擊、下載 PDF、選取選單中的項目或者提交表單) 時,您可以利用 JavaScript 事件處理常式發出 Floodlight 呼叫。
使用者瀏覽器必須已經啟用 Javascript,您才能使用下方所述的方式。如果使用者關閉了 Javascript,您就無法發出 Floodlight 呼叫。
總覽
這種方式的基本前提是利用 Javascript,以動態形式建立 iframe 或圖片代碼 (如果是 Floodlight 圖片代碼的話),以及所有必要的參數,例如自訂變數、銷售相關變數和快取清除。
由於用於定義 Floodlight 活動本身 (類型和類別) 的參數也會顯示在網址中,因此您也可以透過這種方式,從同一個網頁以動態形式呼叫不同的 Floodlight 活動。這對於以 AJAX 撰寫的網頁非常實用。
如要呼叫下方所述的函式,您可以在 HTML 檔案內文中使用 onclick()
或 onsubmit()
函式。如果是會重新導向至到達網頁或檔案下載的 onclick
事件,您必須使用 target="_blank"
屬性,否則重新導向至同一個瀏覽器分頁,將會造成代碼無法正確觸發。
您可以前往以下示範網頁,查看其他類似的有效程式碼範例 (網站管理員可以查閱原始程式碼):https://storage.googleapis.com/dcm-floodlight/Floodlight_on_Click_EXAMPLE.html
我們建議您將所有 JavaScript 函式宣告加入網頁的 <head> 區段。
以下範例使用自訂變數 u1。
<script type="text/javascript" id="DoubleClickFloodlightTag">
//<![CDATA[
function FLOOD1(type, cat, u1) {
var axel = Math.random()+"";
var a = axel * 10000000000000000;
var flDiv=document.body.appendChild(document.createElement("div"));
flDiv.setAttribute("id","DCLK_FLDiv1");
flDiv.style.position="absolute";
flDiv.style.top="0";
flDiv.style.left="0";
flDiv.style.width="1px";
flDiv.style.height="1px";
flDiv.style.display="none";
flDiv.innerHTML='<iframe id="DCLK_FLIframe1" src="http://12345678.fls.doubleclick.net/activityi;src=12345678;type=' + type + ';cat=' + cat + ';u1=' + u1 + ';ord=' + a + '?" width="1" height="1" frameborder="0"><\/iframe>';
}
//]]>
</script>
</head>
<body>
<!-- This is an example of a "onclick" call on a anchor tag -->
<a href="http://address_of_page_to_load_or_file_to_download" onclick="FLOOD1('testtype', 'testcat', 'testu1');" target="_blank">Click here to test the tag</a>
</body>
請注意,使用圖片代碼會造成預設代碼與發布商代碼無法觸發。
<script type="text/javascript" id="DoubleClickFloodlightTag">
//<![CDATA[
function FLOOD2(type, cat, u1) {
var axel = Math.random()+"";
var a = axel * 10000000000000000;
var spotpix = new Image();
spotpix.src="http://ad.doubleclick.net/activity;src=12345678;type=" + type + ";cat=" + cat + ";u1=" + u1 + ";ord=" + a + "?";
}
//]]>
</script>
</head>
<body>
<!-- This is an example of a "onclick" call on a anchor tag -->
<a href="http://address_of_page_to_load_or_file_to_download" onclick="FLOOD2('testtype', 'testcat', 'testu1');" target="_blank">Click here to test the tag</a>
</body>
在這個範例中,如果呼叫的函式所含的 isUnique
值為 1 或通用值,系統就會在呼叫代碼時將其指定為「不重複使用者 24 小時」計數器類型,而如果傳送的值為 0 或省略這個值,系統會在呼叫代碼時將其指定為標準計數器類型。
<script type="text/javascript" id="DoubleClickFloodlightTag">
//<![CDATA[
function FLOOD3(type, cat, isUnique) {
var axel = Math.random()+"";
var a = axel * 10000000000000000;
var flDiv=document.body.appendChild(document.createElement("div"));
var cachebust = (isUnique)?';ord=1;num=':';ord=';
flDiv.setAttribute("id","DCLK_FLDiv1");
flDiv.style.position="absolute";
flDiv.style.top="0";
flDiv.style.left="0";
flDiv.style.width="1px";
flDiv.style.height="1px";
flDiv.style.display="none";
flDiv.innerHTML='<iframe id="DCLK_FLIframe1" src="http://12345678.fls.doubleclick.net/activityi;src=12345678;type=' + type + ';cat=' + cat + cachebust + a + '?" width="1" height="1" frameborder="0"><\/iframe>';
}
//]]>
</script>
</head>
<body>
<!-- This is an example of a "onclick" call on a anchor tag -->
<a href="http://address_of_page_to_load_or_file_to_download" onclick="FLOOD3('testtype', 'testcat', 1);" target="_blank">Click here to test the tag</a>
</body>
請使用以下程式碼建立代碼,同時指定 qty
(活動數)、cost
和 ord
參數,並加上自訂變數 u1。
<script type="text/javascript" id="DoubleClickFloodlightTag">
//<![CDATA[
function FLOOD4(qty, cost, u1, ord) {
var flDiv=document.body.appendChild(document.createElement("div"));
flDiv.setAttribute("id","DCLK_FLDiv1");
flDiv.style.position="absolute";
flDiv.style.top="0";
flDiv.style.left="0";
flDiv.style.width="1px";
flDiv.style.height="1px";
flDiv.style.display="none";
flDiv.innerHTML='<iframe id="DCLK_FLIframe1" src="http://12345678.fls.doubleclick.net/activityi;src=12345678;type=123;cat=456;qty=' + qty + ';cost=' + cost + ';u1=' + u1 + ';ord='+ ord + '?" width="1" height="1" frameborder="0"><\/iframe>';
}
//]]>
</script>
</head>
<body>
<!-- This is an example of a "onclick" call on a anchor tag -->
<a href="http://address_of_page_to_load_or_file_to_download" onclick="FLOOD4(2, 100.34, 'testu1', 'testorderid');" target="_blank">Click here to test the tag</a>
</body>