Rich-text Reply

Total Revenue snippet throwing TypeError

troutoil 08-25-15
Accepted Solution

Total Revenue snippet throwing TypeError

Hi everyone,

I've been using Optimizely for a few years and haven't ever run into any issues. However, I'm stuck trying to implement the Total Revenue goal on my site.

 

I'm stuck on implementing the Total Revenue goal. My confirmation page has my Optimizely snippet in the head, and further down that page I'm using the following code as outlined in the Revenue tracking goals page in the KB.

 

<script>
	var price = '$35.00';
	price = price.replace('$','');
	valueInCents = price * 100;
</script>
<script>
   window.optimizely = window.optimizely || [];
 	   window.optimizely.push(['trackEvent', 'membershipCost', {'revenue': valueInCents}]);
</script>

I continually get the following error whenever I run the push function: TypeError: undefined is not a function (evaluating 'window.optimizely.push(['trackEvent', 'eventName', {'revenue': valueInCents}])').

 

Anyone have any idea what's going on?

Level 1

tomfuertes 08-25-15
 

Re: Total Revenue snippet throwing TypeError

If you're running ghostery or adblock you'll run into this issue b/c window.optimizely won't be an array. Otherwise the code looks good with the exception that you might want to wrap `price` in a `parseInt(price, 10);` before multiplying it by 100.

____
- Tom Fuertes | CTO @ CROmetrics / LinkedIn
"Most Impactful Use of Personalization" and "Experience of the Year" Optie award winner.


troutoil 08-25-15
 

Re: Total Revenue snippet throwing TypeError

That did it! Thanks a ton. I hadn't whitelisted this subdomain in Ghostery.
Level 1