Rich-text Reply

Passing multiple parameters to a custom goal

DuncanC 09-19-14

Passing multiple parameters to a custom goal

[ Edited ]



When completing an order, our customers see a reciept page with details of each product, quantity and price paid.


We'd like to create a function to track sales of individual products (rather than total order revenue) by reading the reciept contents displayed on this page and passing these variables back to an optimizely goal.  We'd need product, quantity and price.


Here's what we have so far:


<script type="text/javascript">

  window.optimizely = window.optimizely || [];

      $('.shoppingBasket tr').each(function() {
         var pName = $(this).find("span.pastorder-productname").text().trim().match(/\w*\s\X\d/g);

         if (pName != null) {
           var pQuantity = $(this).find("td.cart-quantity").text().trim();
           var pRevenue = $(this).find("td.cart-price").text().trim();
           if (pRevenue == "") pRevenue = 0

           window.optimizely.push(['trackEvent', pName, {'quantity': pQuantity, 'price': pRevenue }]);
           console.log(pName + " " + pQuantity + " " + pRevenue);




However, we're not sure that we're able to pass multiple values along as we'd like, all the examples only show passing one variable (e.g. on the revenue example you have).

Is what we want to do possible, or would we need to call multiple push events and pass each quantity/revenue pair back to a different goal for each product?


Has anyone done this before, and if so how did you go about it?


Many thanks!

Level 2

Amanda 09-19-14

Re: Passing multiple parameters to a custom goal

Hey @DuncanC , This is a great question. 


Check out this discussion and answer from @Gary , as I beleive it should answer your question. Does that solve for what you are looking for? Let me know if you have additional questions and we'd be happy to provide more details!