0

I am trying to enable revenue tracking in Optimizely.

I have customized the jQuery snippet that the Optimizely knowledge base provides and installed it on the last page prior to the completion of the checkout process.

Here is the "Complete Booking" button that I am trying to connect my snippet to:

onmousedown I want to fire this function:

<script type="text/javascript">
  var optimizely = optimizely || [];
  $("input[value='Complete Booking'].submit").live("mousedown", function() {
     optimizely.push(['trackEvent', 'booking_complete', total]);
  });
</script>

There is a variable called total that exists elsewhere in the DOM that has the total price of the item purchased.

However, when I install this script, it does not track revenue. I suspect a jQuery issue in my rewrite of the official Optimizely function. Does anyone have some insight into this?

Update

I realized that I probabally need to call $(document).ready(function() in order for the jQuery to trigger. I also am now passing the value in cents rather than dollars. Also tried using .submit() rather than .onmousedown(). I also changed the value in the push to add_cart_button_clicked, just like in the revenue tracking tutorial on Optimizely's site. Here is my updated code, but it is still not working.

<script type="text/javascript">
    $(document).ready(function(){
        var optimizely = optimizely || [];
        var revenueInCents = total * 100;
        $("input[value='Complete Booking'].submit").submit(function() {
            optimizely.push(['trackEvent', 'add_cart_button_clicked', revenueInCents]);
        });
    }
</script>
TrentonMcManus
  • 487
  • 1
  • 7
  • 16
  • 1
    It's probably not working because you're pushing "booking_complete" event on a button that is probably submitting a form. So user is taken from a page before your tracking call can be even processed. – WTK Oct 07 '11 at 08:36
  • 2
    First, be sure that `total` is a cents value. ie, $4.53 should be passed as 453. Second, can you confirm your jQuery selector is correct? should `.submit` (a CSS class) be `:submit` (a sizzle selector)? – Yahel Oct 08 '11 at 02:03
  • The `total` does need to be in cents @yahelc. Good call on that one. I am also including the code of the button that I am trying to get attach the action to: `` – TrentonMcManus Oct 10 '11 at 04:33

1 Answers1

0

Optimizely's changed their revenue tracking API since this question was posted.

https://help.optimizely.com/hc/en-us/articles/200039865-Revenue-Tracking

$(function(){
  window.optimizely = window.optimizely || [];
  var revenueInCents = total * 100;
  $("form#id").submit(function() {
    window.optimizely.push([
      'trackEvent', 
      'add_cart_button_clicked', 
      {revenue: revenueInCents}
    ]);
  });
});
TomFuertes
  • 7,150
  • 5
  • 35
  • 49