2015-05-20 3 views
0

Я пытаюсь перенести отслеживание электронной торговли Google Analytics E на универсальный, но у меня есть несколько проблем. Само отслеживание работает нормально, но не электронной коммерции. Я включил отслеживание электронной торговли в Google Analytics и добавил следующий код:Данные Google Analytics Universal Ecommerce не записываются

внутри printerlandtest.co.uk.cara.init.js:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

ga('create', 'UA-30033504-40', 'auto',{'name': 'CARATracker'}); // New tracker. 
ga('CARATracker.send', 'pageview'); 

и внутри caranew.js

ga('CARATracker.require', 'ec'); 


function CaraGetWidgetDescription(manufacturerWidget) { 
    CaraConfig(); 
    ga('CARATracker.set', 'Widget Impression ID E-tale', String(manufacturerWidget)); 

} 



function CaraAddToBasket(productName, sku) { 

    CaraConfig(); 
    ga('CARATracker.send', 'event', String(productName), 'AddToBasket', String(sku)); 
} 

function CaraBeginTransaction(orderNo, totalPrice) { 

CaraConfig(); 
    ga('CARATracker.ecommerce:addTransaction', String(orderNo), "", CaraPriceFix(String(totalPrice)), "", "0.00", "", "", ""); 
} 

function CaraAddTransactionItem(orderNo, sku, productName, productCategory, productPrice, quantity) { 

    CaraConfig(); 
    ga('CARATracker.ecommerce:addItem', { 
     String(orderNo), 
     String(sku), 
     String(productName), 
     String(productCategory), 
     CaraPriceFix(String(productPrice)), 
     String(quantity) 
    }); 


function CaraEndTransaction() { 

    CaraConfig(); 
    ga('CARATracker.ecommerce:send'); 
} 

function CaraPriceFix(price) { 

    var fixedPrice = price; 

    var pLength = price.length; 
    var comma = price.indexOf(",") + 1; 
    var period = price.indexOf(".") + 1; 

    //comma is in the price 
    if (comma != 0) { 
     //if the comma is not at a 2-decimal point position 
     //i.e true for 1,200 
     if ((pLength - comma) > 2) { 
      fixedPrice = fixedPrice.replace(",", ""); 
     } 
    } 
    //period is in the price 
    if (period != 0) { 
     //if the period is not at a 2-decimal point position 
     //i.e true for 1.200 
     if ((pLength - period) > 2) { 
      fixedPrice = fixedPrice.replace(".", ""); 
     } 
    } 
    return fixedPrice; 
} 

поскольку это внутри сайта clents это асинхронно с использованием собственных аналитических Google и устанавливается следующим образом:

<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-3521256-1', {'siteSpeedSampleRate': 20}); ga('send', 'pageview');</script><script src="https://where-to-buy.co/scripts/cara/printerlandtest.co.uk.cara.init.js" type="text/javascript"></script><script src="https://where-to-buy.co/scripts/cara/caranew.js" type="text/javascript"></script> 

На кнопку Добавить в корзину их есть следующий код:

<a onclick="TrackEvent('Buy Button Click','ProductList','01327701','');CaraAddToBasket('OKI C511dn','01327701');" id="ctl00_ctl00_ContentPlaceHolderMain_cntPlaceHlderMain_lstCategoryProducts_ctrl0_lnkBuy" class="button product_buy selected" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$ContentPlaceHolderMain$cntPlaceHlderMain$lstCategoryProducts$ctrl0$lnkBuy", "", true, "", "", false, true))'><span>Added</span> </a> 

Однако я получаю следующее сообщение об ошибке:

Uncaught ReferenceError: CaraAddToBasket не определен

и когда я нажимаю на Pay я получаю следующую ошибку:

Uncaught ReferenceError: CaraBeginTransaction не def ined

Я думал, что определяю их в функциях, но имею ли я что-то не так?

Есть ли что-нибудь еще, что останавливает отслеживание электронной торговли?

Thanks

ответ

1

Я переписал код и пришел к этому решению. Удаление всех новых функций String() и перемещение функции исправления цены из массива в var выше этого.

Кроме того, отсутствовала функция addtobasket, которая приводила к сбою JS.

Теперь функция работает нормально.

(function(i, s, o, g, r, a, m) { 
 
    i['GoogleAnalyticsObject'] = r; 
 
    i[r] = i[r] || function() { 
 
    (i[r].q = i[r].q || []).push(arguments) 
 
    }, i[r].l = 1 * new Date(); 
 
    a = s.createElement(o), 
 
    m = s.getElementsByTagName(o)[0]; 
 
    a.async = 1; 
 
    a.src = g; 
 
    m.parentNode.insertBefore(a, m) 
 
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); 
 

 
ga('create', 'UA-30033504-40', 'auto', { 
 
    'name': 'CARATracker' 
 
}); // New tracker. 
 
ga('CARATracker.send', 'pageview'); 
 

 
ga('CARATracker.require', 'ec'); 
 

 

 
function CaraGetWidgetDescription(manufacturerWidget) { 
 
    CaraConfig(); 
 
    ga('CARATracker.set', 'Widget Impression ID E-tale', String(manufacturerWidget)); 
 

 
} 
 

 

 

 
function CaraAddToBasket(productName, sku) { 
 

 
    CaraConfig(); 
 
    ga('CARATracker.send', 'event', String(productName), 'AddToBasket', String(sku)); 
 
    alert('Debugging: added'); 
 
} 
 

 
function CaraBeginTransaction(orderNo, totalPrice) { 
 

 
    CaraConfig(); 
 
    ga('CARATracker.ecommerce:addTransaction', String(orderNo), "", CaraPriceFix(String(totalPrice)), "", "0.00", "", "", ""); 
 
} 
 

 
function CaraAddTransactionItem(orderNo, sku, productName, productCategory, productPrice, quantity) { 
 

 
    CaraConfig(); 
 
    var price = CaraPriceFix(productPrice); 
 
    alert(price); 
 
    ga('CARATracker.ecommerce:addItem', { 
 
    orderNo, 
 
    sku, 
 
    productName, 
 
    productCategory, 
 
    price, 
 
    quantity 
 
    }); 
 
} 
 

 

 
function CaraEndTransaction() { 
 

 
    CaraConfig(); 
 
    ga('CARATracker.ecommerce:send'); 
 
} 
 

 
function CaraPriceFix(price) { 
 

 
    var fixedPrice = price; 
 

 
    var pLength = price.length; 
 
    var comma = price.indexOf(",") + 1; 
 
    var period = price.indexOf(".") + 1; 
 

 
    //comma is in the price 
 
    if (comma != 0) { 
 
    //if the comma is not at a 2-decimal point position 
 
    //i.e true for 1,200 
 
    if ((pLength - comma) > 2) { 
 
     fixedPrice = fixedPrice.replace(",", ""); 
 
    } 
 
    } 
 
    //period is in the price 
 
    if (period != 0) { 
 
    //if the period is not at a 2-decimal point position 
 
    //i.e true for 1.200 
 
    if ((pLength - period) > 2) { 
 
     fixedPrice = fixedPrice.replace(".", ""); 
 
    } 
 
    } 
 
    return fixedPrice; 
 
} 
 

 
function CaraConfig() { 
 
    //empty 
 
}
<html> 
 

 
<body> 
 
    <a onclick="CaraAddToBasket('OKI C511dn','01327701');" id="ctl00_ctl00_ContentPlaceHolderMain_cntPlaceHlderMain_lstCategoryProducts_ctrl0_lnkBuy" class="button product_buy selected" href='#'><span>Added</span> </a> 
 

 
</body> 
 

 
</html>

+0

Спасибо, я только что заметил, дополнительный} aswel хороший старый пульт он выглядит, как он должен работать сейчас UST придется ждать данных, чтобы прийти через на аналитике (пальцы скрещены) спасибо за ваш время. Я фактически удалил CaraConfig(); как я считаю его устаревшим. – anna

+0

привет Томасу, к сожалению, я до сих пор не получаю данные электронной коммерции, даже если предупреждения, установленные в коде, попадают. Есть ли у вас другие предложения? В обзоре поведения я вижу, что страница orderreceipt.aspx попадает, но нет данных электронной торговли. Большое спасибо – anna

+0

извините, не поделили вас последним комментарием, пожалуйста, смотрите, спасибо! – anna

Смежные вопросы