将Google Analytics电子商务代码段中的收入数据提取到另一个收入跟踪代码段中

时间:2014-04-02 18:42:06

标签: javascript google-analytics analytics optimizely

我们目前在表单感谢页面上设置了Google Analytics电子商务跟踪功能。我们还使用Optimizely在我们的网站上运行A / B / n测试。优化的在线拆分测试平台,也可以配置收入跟踪。

我们希望获得Optimizely收入跟踪和运行,但受到表单推送代码的限制。 我希望找到一个解决方案,我们可以将GA电子商务代码段中的收入数据提取到同一页面上的Optimizely代码段中。

以下是GA电子商务代码段:

//Ecommerce Tracking Code 
if (pageName == 'thankyou') { 
    //Pull apart and use pieces of the HTML Document.Title
    //where proposed convention is :: Fund - eventName - eventVersion
    //changes based on provided example: 
    var pageIdentity = document.title;

    var parsePageName = pageIdentity.split(" - ");
    var fundName = parsePageName[0];        
    var eventName = parsePageName[1];
    var eventVersion = parsePageName[2];


    var paymentType = "oneTimeCreditCard";
    var donationAmount = "$5.00";
    var constituentID = "13921362";
    var eventID = gup('eventid')||gup('eid');


    //handles ecommerce transaction variables populated for GA
    amount = getPaymentAmount("#ctl00_ctl00_mainContent_bodyContentPlaceHolder_hidDonationAmount"); 

    pageTracker2._addTrans(constituentID, "PaymentNew", amount,"","","","",""); 
    pageTracker2._addItem(constituentID, eventID,fundName+"-"+eventName,paymentType,amount,"1");
    pageTracker2._trackTrans();    
} // if donatethankyou

我们正在尝试将donationAmount变量(或等效内容)拉入Optimizely代码段:

window.optimizely = window.optimizely || [];
window.optimizely.push(['trackEvent', 'eventName', {'revenue': valueInCents}]);

目前的设置是否可以实现?我的JS(显然)非常生疏。

提前致谢!

1 个答案:

答案 0 :(得分:2)

您可以使用当前设置。

//initiates Optimizely code if it's been loaded, if not queue the function calls in a JavaScript array.
window.optimizely = window.optimizely || [];

    //takes the string for donationAmount variable, replaces the $, converts to string, and multiplies by 100
    var totalPrice = Number(donationAmount.replace(/\$|,/g, '')) * 100;

    //pushes event to optimizely with total.
    window.optimizely.push(['trackEvent', 'thankYouPage', {
        'revenue': totalPrice
}]);

您还需要设定两个目标:

自定义事件(负责优化事件) enter image description here

收入(用于查看实验中的收入) enter image description here