Google Publisher Tag 的 Audience Manager 代码 audience-manager-code-for-google-publisher-tags

AamGpt 是 JavaScript 讀取Audience ManagerCookie資料並將該資訊傳送至的函式 Google Publisher Tags.

NOTE
如果您有自己的程式碼,可以讀取Audience ManagerCookie資料,則不需要使用此函式。 UUID 和目的地Cookie。

示例代码

放置 AamGpt 程式碼放置在頁面頂端,最好是在 <head> 程式碼區塊。 此 AamGpt 程式碼提供如下:

var AamGpt = {
 strictEncode: function(str){
  return encodeURIComponent(str).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
 },
 getCookie: function(c_name)
 {
  var i,x,y,c=document.cookie.split(";");
  for (i=0;i<c.length;i++)
  {
   x=c[i].substr(0,c[i].indexOf("="));
   y=c[i].substr(c[i].indexOf("=")+1);
   x=x.replace(/^\s+|\s+$/g,"");
   if (x==c_name)
   {
    return unescape(y);
   }
  }
 },
 getKey: function(c_name){
  var c=this.getCookie(c_name);
  c=this.strictEncode(c);
  if(typeof c != "undefined" && c.match(/\w+%3D/)){
   var cList=c.split("%3D");
   if(typeof cList[0] != "undefined" && cList[0].match(/\w+/))
   {
    return cList[0];
   }
  }
 },
 getValues: function(c_name){
  var c=this.getCookie(c_name);
  c=this.strictEncode(c);
  if(typeof c != "undefined" && c.match(/\w+%3D\w+/)){
   var cList=c.split("%3D");
   if(typeof cList[1] != "undefined" && cList[1].match(/\w+/))
   {
    var vList=cList[1].split("%2C");
    if(typeof vList[0] != "undefined")
    {
     return vList;
    } else {
     return null;
    }
   } else {
    return null;
   }
  } else {
   return null;
  }
 }
};
recommendation-more-help
de293fbf-b489-49b0-8daa-51ed303af695