2013-12-12 36 views
0

推自定義變量我使用GA代碼在我的網站像下面與谷歌標籤管理

<script type="text/javascript" language="javascript"> 
        var _gaq = _gaq || []; 
        _gaq.push(['_setAccount', 'UA-xxxxxx-1']); 
        _gaq.push(['_setDomainName', '.myweb.co.uk']); 
if (source != '') { 
         _gaq.push(function() { 
          extga._setCampValues(source, medium, name); 
         }); 
        } 
        // Set the custom variable ranking 
        var url = String(document.referrer); 
        // confirm they came from G 
        if (url.indexOf("google.co") != -1 || url.indexOf("google.be") != -1 || url.indexOf("google.ie") != -1 || url.indexOf("google.fr") != -1) { 

         var urlVars = {}; 
         var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { 
          urlVars[key] = value; 
         }); 
         // Push to GA Custom Variables 
         _gaq.push(['_setCustomVar', '1', 'Keywords Rankings', urlVars["cd"], 1]); 
        } 
        //Track the record in GA 
        _gaq.push(['_trackPageview']); 

        (function() { 
         var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
         ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'; 
         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
        })(); 
       </script> 

現在我想更換與谷歌代碼管理工具GA代碼。我的問題是,我們如何使用Google標記managera在Google Analytics上推送cstom變量,目前我正在使用_gaq.push方法爲廣告系列推送自定義數據。

問候, 哈比卜

回答

2

另一種選擇是使用自定義Javascript宏來處理自定義變量。你可以把你的整個組自定義變量的排名中它:

function(){ 
var url = {{referrer}}; //there is a GTM macro for the HTTP referrer 

// confirm they came from G 
if (url.indexOf("google.co") != -1 || url.indexOf("google.be") != -1 || url.indexOf("google.ie") != -1 || url.indexOf("google.fr") != -1) { 

    var urlVars = {}; 

    var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { 
     urlVars[key] = value; 
    }); 

// Return the Custom Variable value 
return urlVars["cd"]; 
} 

}

*注意,我沒有測試此代碼,但它應該是八九不離十。

然後你可以使用該宏,你可能命名它像{{customVar1Val}}並把它插入到谷歌Analytics(分析)標籤:

enter image description here

+0

感謝Blexy的幫助 –

+0

您好我也使用_gaq.push(['_ trackPageview','/ activity-weekends/inquiry /']);將自定義目標推送到GA,我們如何在GTM中處理這個問題。謝謝 –

2

一旦你移動到谷歌代碼管理工具,您_gaq.push()dataLayer.push()取代。 在內部,dataLayer.push()在標籤觸發規則被觸發時調用_gaq.push()。

創建Google Analytics(分析)tag並使用您的帳戶,域名等進行配置。默認情況下,它會在所有頁面上使用射擊rule運行。

您既可以使用GUI來管理GA配置,也可以使用自定義html代碼段並粘貼代碼。

您將要使用macros來構建自定義變量。 使用自定義JavaScript宏,你可以重用你現有的代碼。然後將這個宏包含在你的GA標籤中。

1

你的問題可以在Tag Manager developers guide回答。甚至有一節叫做Migrating Tags to Google Tag Manager,您可以在其中閱讀

...本節介紹最佳實踐遷移工作流程。該過程有5個主要步驟:

  1. 地圖網站(可選)
  2. 列表項
  3. 執行標準谷歌標籤管理器代碼段
  4. 添加事件和變量
  5. 添加標籤,在相關發射規則谷歌代碼管理工具的管理界面
  6. 最終遷移交換
相關問題