Created
March 22, 2013 18:31
-
-
Save twanlass/5223629 to your computer and use it in GitHub Desktop.
Example - using embedded checkout with Google Analytics for tracking sales.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <title>Example Checkout w/ Google Analytics Tracking</title> | |
| </head> | |
| <body> | |
| <!-- Need this included just once on any page you're selling something. Best to probably globally include it. --> | |
| <script type="text/javascript" src="https://www.simplegoods.co/assets/embed.js"></script> | |
| <!-- You probably already have jQuery included in your site. Here for completeness --> | |
| <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
| <!-- Listens for a success event then sends Google information about the sale --> | |
| <script type="text/javascript"> | |
| $(document).ready(function() { | |
| $("body").on("success", "#SGEmbed", function(e){ | |
| trackSale(e.originalEvent.detail) | |
| }); | |
| function trackSale(data) { | |
| _gaq.push(['_addTrans', | |
| data.transaction_id, // transaction ID - required | |
| 'BGH Store', // affiliation or store name | |
| data.price, // total - required | |
| ]); | |
| _gaq.push(['_addItem', | |
| data.transaction_id, // transaction ID - required | |
| data.product_name, // SKU/code - required | |
| data.product_name, // product name | |
| data.product_price, // unit price - required | |
| '1' // quantity - required | |
| ]); | |
| _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers | |
| } | |
| }); | |
| </script> | |
| <!-- Standard Google Analytics Tracking Code --> | |
| <script type="text/javascript"> | |
| var _gaq = _gaq || []; | |
| _gaq.push(['_setAccount', 'UA-35919906-1']); | |
| _gaq.push(['_setDomainName', 'simplegoods.co']); | |
| _gaq.push(['_trackPageview']); | |
| (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> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment