Question

We currently have Google Analytics ecommerce tracking set up on our form thank-you pages. We're also using Optimizely to run A/B/n tests on our website. Optimizely's an online split-testing platform, that also has revenue tracking you can configure.

We'd like to get Optimizely revenue tracking up and running, but are limited with what the form can push out code-wise. I'm hoping to find a solution where we can pull the revenue data from the GA ecommerce snippet into the Optimizely snippet on the same page.

Here is the GA e-commerce snippet:

//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

and we're trying to pull the donationAmount variable (or equivalent) into the Optimizely snippet:

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

Is this possible with the current setup? My JS is (clearly) very rusty.

Thanks in advance!

Was it helpful?

Solution

It is possible with your current setup.

//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
}]);

You'll also need to set up two goals:

Custom event (responsible for getting the event into optimizely) enter image description here

Revenue (for seeing revenue in your experiment) enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top