Google Analytics and the Checkout.

433 views
Skip to first unread message

Ryan

unread,
Oct 18, 2010, 10:16:25 AM10/18/10
to Spree
Hi everyone,

I'm trying to setup Google Analytics reporting to set up goals and
track progress through the checkout which requires urls to monitor
each step (this will help for funnel visualization) however in the
checkout the entire checkout process uses the same url i.e. /orders/
R844142541/checkout so it is not possible to distinguish which step
the user leaves the checkout. Ideally it needs to be:

/orders/R844142541/checkout/address
/orders/R844142541/checkout/shipping
/orders/R844142541/checkout/payments

This would allow a RegEx so we could do something like /orders/R[0-9]
{1,8}/checkout/(address|shipping|payments) to monitor the progress.

Has anyone else manage to successfully set this up, or is there an
alternative method?

Regards

Ryan

Sean Schofield

unread,
Oct 18, 2010, 10:16:54 PM10/18/10
to spree...@googlegroups.com
These URL's are actually not the ones sent to GA. GA allows you to
"spoof" your own URL so they show up in a more meaningful way. I'm
describing 0-11-x btw. In the edge code its even simpler because
we've simplified the URL's and no spoofing is necessary. The URL's
are already meaningful and the specific order number has been dropped
(so no regex needed.)

Sean Schofield

-------------------------------------------
Rails Dog LLC
2 Wisconsin Circle, Suite 700
Chevy Chase, MD 20815
voice: (301)560-2000
-------------------------------------------

> --
> You received this message because you are subscribed to the Google Groups "Spree" group.
> To post to this group, send email to spree...@googlegroups.com.
> To unsubscribe from this group, send email to spree-user+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spree-user?hl=en.
>
>

Diccon

unread,
Nov 19, 2010, 9:44:40 AM11/19/10
to Spree
So we'd be right in assuming there is currently no Core Spree
components or Extension that does Google Analytics eCommerce tracking?

I ask because if so, and there is no one working on it, I will try and
write it as an extension for ourself's and publish it.

Share the wealth and all that :)

Diccon

Steph Skardal

unread,
Nov 19, 2010, 9:55:50 AM11/19/10
to spree...@googlegroups.com
Spree does Google Analytics ecommerce tracking. Below is the core view
that includes the Google Analytics ecommerce tracking in Spree 0.11.2.

I'm pretty sure there would have been no reason to take this out of
Spree edge, so I'm assuming it's still there.


~Steph


<% if tracker = Tracker.current %>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ?
"https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost +
"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>

<script type="text/javascript">
var pageTracker = _gat._getTracker("<%= tracker.analytics_id %>");
pageTracker._initData();

/* Standard analytics or "virtual page" (useful for goal tracking
and funnel stuff) plus optional E-Commerce conversion */
<% if flash[:analytics] %>
pageTracker._trackPageview("<%=flash[:analytics]%>");
<% else %>
pageTracker._trackPageview();
<% end %>

<% if flash[:commerce_tracking] %>
// report e-commerce transaction information when applicable
pageTracker._addTrans(
"<%= @order.number %>", //Order Number
"", //Affiliation
"<%= @order.total %>", //Order total
"<%= @order.tax_charges.sum(:amount).to_s %>", //Tax Amount
"<%= @order.shipping_charges.sum(:amount).to_s %>",
//Ship Amount
"", //City
"", //State
"" //Country
);
<% @order.line_items.each do |line_item| -%>
pageTracker._addItem("<%= @order.number %>", "<%=
line_item.variant.sku %>", "<%= line_item.variant.product.name %>",
"" /*Product Category*/, "<%= line_item.price %>", "<%=
line_item.quantity %>");
<% end -%>
pageTracker._trackTrans();

<% end %>
</script>
<% end %>

Sean Schofield

unread,
Nov 19, 2010, 10:13:15 AM11/19/10
to spree...@googlegroups.com

Correct.  It's included in edge as well as 0.30.x

aschmid

unread,
Nov 19, 2010, 10:36:24 AM11/19/10
to Spree
In case anyone is interested, here is the google analytics view,
updated to use google's asynchronous tracking code. Note that google
recommends this go right before the closing </head> tag, so the
google_analytics partial should be rendered in the head, rather than
footer partial.

Andrew

<% if tracker = Tracker.current %>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<%= tracker.analytics_id
%>',"_trackPageview"]);

<% if flash[:commerce_tracking] %>
// report e-commerce transaction information when applicable
_gaq.push(['_addTrans',
'<%= @order.number %>', // order ID - required
'', // affiliation or store name
'<%= @order.total %>', // total - required
'<%= @order.adjustments.tax.sum(:amount).to_s
%>', // tax
'<%= @order.adjustments.shipping.sum(:amount).to_s
%>', // shipping
'<%= @order.ship_address.city %>', // city
'<%= @order.ship_address.state.name %>', // state or
province
'<%= @order.ship_address.country.name %>' //
country
]);
<% @order.line_items.each do |line_item| -%>
_gaq.push(["_addItem",
"<%= @order.number %>",
"<%= line_item.variant.sku %>",
"<%= line_item.variant.product.name %>",
"",
"<%= line_item.price %>",
"<%= line_item.quantity %>"]);
<% end -%>

_gaq.push(["_trackTrans"]);

<% end %>
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ?
'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
<% end %>

Diccon

unread,
Nov 19, 2010, 10:49:07 AM11/19/10
to Spree
Bingo, thanks guys.
We must have knocked the Tracker off with a customization. Bug hunting
time :)

Cheers.
Diccon
> > components or Extension that does GoogleAnalyticseCommerce tracking?

Diccon

unread,
Nov 19, 2010, 12:22:17 PM11/19/10
to Spree
Found it; multi_domain extension was stepping on toes.

aschmid: your Asynchronous updated Tracker seems to be working well
thus far, thanks. Solid proof will come monday.
Others had suggested it's wise to step up to Googles latest
Asynchronous way of handling Analytics.

Ryan: apologies for hijacking your thread.

Diccon

unread,
Nov 29, 2010, 1:10:16 PM11/29/10
to Spree
Just wanted to follow up on this Asyncronous snippet.

Turns out there was a slight syntax difference that was causing
aschmid's patch to not submit GA data of any kind properly, let alone
ecommerce.
The "_trackPageview" had to be in a separate ga.push statement as
shown in the below alteration.

The customers GA advisor actually spotted this and once corrected
everything started coming right.

Hope this helps anyone who uses this:

Should probably branch and patch a proper copy of 0.11 to get it
exactly right. I'll do this if i get time.

<% if tracker = Tracker.current %>
  <script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', '<%= tracker.analytics_id> %>']);
_gaq.push(["_trackPageview"]);
Diccon

aschmid

unread,
Nov 29, 2010, 2:41:14 PM11/29/10
to Spree
Sorry Diccon, looks like there was a typo and a missed a '['
character. You actually don't need separate push statements, but each
item needs to be it's own array. So

_gaq.push(['_setAccount', '<%= tracker.analytics_id%>'],
["_trackPageview"]);

is equivalent to

_gaq.push(['_setAccount','<%= tracker.analytics_id%>']);
_gaq.push(['_trackPageview']);

Thanks for pointing out the mistake

Sean Schofield

unread,
Nov 29, 2010, 3:15:10 PM11/29/10
to spree...@googlegroups.com
I'd be interested in seeing a formal patch for this if anyone is up to
generating a pull request (for Rails 0.30.x and up.)

Sean Schofield

-------------------------------------------
Rails Dog LLC
2 Wisconsin Circle, Suite 700
Chevy Chase, MD 20815
voice: (301)560-2000
-------------------------------------------

Denis (jumph4x)

unread,
Mar 28, 2011, 8:10:00 PM3/28/11
to spree...@googlegroups.com, Sean Schofield

Sean Schofield

unread,
Mar 28, 2011, 9:01:16 PM3/28/11
to spree...@googlegroups.com
Pulled. Thanks.
Reply all
Reply to author
Forward
0 new messages