I've developed a rather novel way of setting up funnel and goal tracking for Google Analytics. Because Squirrelcart uses the same URL (index.php) for all steps of the checkout process, you need to somehow tell Google which step the customer is at in the process.
Here's how I did it.
First, make sure you have the Google Analytics NEW code in your store_main.tpl.php, in the HEAD section.
Then, in checkout.tpl.php, you need to find:Code:<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("UA-XXXXXX-1"); pageTracker._trackPageview(); </script>
and under it, add:Code:<!-- Template: <?php print basename(__FILE__) ?> -->
This gives us access to jquery, so we can do the rest of the processing.Code:<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
At the very end of checkout.tpl.php, add the following:
What this does is to check which step is currently active, by checking the DIV tags that say:Code:<script type="text/javascript" language="javascript"> <!-- if($($("[class^=step1]")).hasClass("active")) pageTracker._trackPageview("/funnel_G1/step1.html"); if($($("[class^=step2]")).hasClass("active")) pageTracker._trackPageview("/funnel_G1/step2.html"); if($($("[class^=step3]")).hasClass("active")) pageTracker._trackPageview("/funnel_G1/step3.html"); if($($("[class^=step4]")).hasClass("active")) pageTracker._trackPageview("/funnel_G1/step4.html"); --> </script>
Step 1 Confirm Items
Step 2 Enter Address
Step 3 Choose Shipping
Step 4 Submit Payment
across the top of the checkout pages. If you notice, when you're checking out, each step you're on is highlighted blue. The jquery script above checks to see which step is highlighted blue and then sends Google a pagetracker for each step. NOTE: If the code for those steps changes in Squirrelcart with a future update, it may break this script.
Finally, in checkout_done.tpl.php, find
and under it, addCode:<div class="checkout_done"> <?php print $Extra_HTML ?> <?php print $Order_Detail ?> </div>
You may also need to add a 1x1 white GIF in your /images directory, if there's not already one there.Code:<img src="/images/blank.gif" onload="pageTracker._trackPageview("/funnel_G1/step5.html"); " />
Then, login to your Google Analytics page, and go into the Goal Setup section.
Make sure it's set to "Head Match"
In the Goal URL field, put https://www.mysite.com/funnel_G1/step5.html
Then, in the funnel fields:
Step 1 = http://www.mysite.com/funnel_G1/step1.html
Step 2 = https://www.mysite.com/funnel_G1/step2.html
Step 3 = https://www.mysite.com/funnel_G1/step3.html
Step 4 = https://www.mysite.com/funnel_G1/step4.html
This works for me, and I'm sure that there may be an easier and more elegant solution, but I thought I would share.


Reply With Quote



