0

我試圖將daysLeft變量傳遞給Google Tag Manager數據層,但它不起作用。如果我使用這個;爲什麼變量沒有傳遞到Google Tag Manager的數據層

var newname = 'daysLeft'; 

它觸發標籤,但在報告中顯示爲daysLeft。如果我嘗試使用標籤

var newname = daysLeft; 

標籤不起作用。

 <script type="text/javascript"> 
    var today = new Date(); // Get todays date. 
    var bookedDate = new Date('June 29, 2014'); // Fill this with the date of the booking in this format - June 29, 2013. 
    var msPerDay = 24 * 60 * 60 * 1000 ; // Work out the number of milliseconds in a day. 
    var timeLeft = (bookedDate.getTime() - today.getTime()); // Booked date minus todays tate, returned in milliseconds. 
    var e_daysLeft = timeLeft/msPerDay; // Divide millieseconds left untill booking by the number of milliseconds in a day. 
    var daysLeft = Math.floor(e_daysLeft); // Round the total down to the nearest integer. 

    var newname = daysLeft; 

    dataLayer = [{'event' : 'newname' }]; 

    </script> <!-- Google Tag Manager --> 
    <noscript><iframe height="0" src="//www.googletagmanager.com/ns.html?id=" 
    style="display:none;visibility:hidden" width="0"></iframe></noscript> 
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': 
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], 
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 
    '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); 
    })(window,document,'script','dataLayer',''); 
    </script> <!-- End Google Tag Manager --> 

回答

1

解決了它,出於某種原因,dataLayer不會傳遞整數。

我不得不把它與

daysLeft.toString(); 
先轉換成字符串
相關問題