Dirty Butter Posted December 21, 2014 Share Posted December 21, 2014 Am I correct that the Google code needed to report sales to Analytics is in content.receipt.php? I use Paypal Standard on our 5.2.14 Blueprint store and our Kurouto 5.2.14 store. Does the customer have to return to our store after payment to the receipt "thank you" page in order for Analytics to get information about the sale? Or does CC send the sale information to Google when the transaction is logged? I ask, because I have never seen any conversion information on Google Analytics. What do I have to do to see sales information in relation to site visits? This is the first year we have spent for Google Adwords, so it's now important that I understand if those advertising dollars might be worthwhile or not. Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 22, 2014 Share Posted December 22, 2014 "Does the customer have to return to our store after payment to the receipt "thank you" page in order for Analytics to get information about the sale?" That's how I see it. The GA code is all javascript and as such, must run in the browser. Who's browser? I suppose it does not matter -- if you can emulate a customer requesting an order's receipt page. I suppose the same GA code could be added to the admin template orders.print.php, so that when you print the shipping manifest, the GA javascript will execute in your browser. This assumes that, if GA receives info about an order more than once, regardless where it actually came from (IP address), the second and any later notification will be ignored. This is an assumption based on the logical reasoning of what should happen if a customer requests the receipt page more than once. Do you want to try an experiment to add GA to the admin's shipping manifest? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 22, 2014 Author Share Posted December 22, 2014 That sounds doable! Almost no one ever comes back to the "thank you" receipt page. Once they've paid on PP, that's the end for them, as it would be for me. Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 22, 2014 Share Posted December 22, 2014 Actually, the template content.receipt.php is called when CubeCart determines the order is "complete" -- which is when the customer returns to your store from the payment gateway (on gateways where the customer never leaves the store, the "complete" phase is guaranteed). This is not when the customer asks for a receipt from their Accounts section. I don't do GA, and so cannot test this, so you will need to be prepared to have mistakes in the code. In the skin file content.receipt.php, find the GA code. It starts with {if $ANALYTICS}<script> and ends with </script>{/if}. In the admin template orders.print.php, create a new blank line just above {/foreach}{/if}</body></html>. Copy the GA code onto this new blank line. Now we have to populate the skin variables $ANALYTICS, $GA_SUM, and $GA_ITEMS. We will borrow the code from CubeCart->_complete(). In the file admin/sources/orders.index.inc.php, find near line 467: $label_fix = array('ship_method','ship_tracking','gateway'); foreach ($summary as $key => $value) { if (empty($value) && in_array($key,$label_fix)) $summary[$key] = ' '; } Add above it, this: // Analytics if(in_array($summary['status'],array(2,3))) { $ga_id = $GLOBALS['config']->get('config', 'google_analytics'); $ga_id = trim($ga_id); $GLOBALS['smarty']->assign('ANALYTICS', !empty($ga_id) ? $ga_id : false); $GLOBALS['smarty']->assign('GA_ITEMS', $inventory); $vars['ga_sum'] = $summary; $vars['ga_sum']['country_iso'] = getCountryFormat($summary['country'], 'numcode', 'iso'); $vars['ga_sum']['google_id'] = $GLOBALS['config']->get('config', 'google_analytics'); $vars['ga_sum']['store_name'] = $GLOBALS['config']->get('config', 'store_name'); $GLOBALS['smarty']->assign('GA_SUM', $vars['ga_sum']); } There is a hook available in CubeCart->_complete(), 'class.cubecart.construct.complete', which offers plugins and snippets to do some preliminary work prior to CubeCart collecting/organizing the data to be displayed in the order complete "receipt". I think not including this hook in this experiment will not be a problem. Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 22, 2014 Share Posted December 22, 2014 I think there also needs to be the javascript that creates the ga() function. So far, we have only copied the code that executes the ga() function for order conversions. So, from the skin template file main.php, copy the code that starts with {if $ANALYTICS}{literal} and ends with {/literal}{/if}, to a place in the admin template orders.print.php just above the </head> statement as shown here: {if $ANALYTICS} {literal}<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', '{/literal}{$ANALYTICS}{literal}', 'auto'); // Replace with your property ID. ga('send', 'pageview'); </script>{/literal} {/if} </head> We do not need the 'pageview' command, so: ga('send', 'pageview'); can probably be removed. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 22, 2014 Author Share Posted December 22, 2014 Actually, the template content.receipt.php is called when CubeCart determines the order is "complete" -- which is when the customer returns to your store from the payment gateway (on gateways where the customer never leaves the store, the "complete" phase is guaranteed). This is not when the customer asks for a receipt from their Accounts section. That's what I thought, as Standard PP does NOT send the customer back to CC, but only an inconspicuous link is provided to return. I'll do some backing up and give your edits a try in a bit. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 22, 2014 Author Share Posted December 22, 2014 Edits are now in place. What do I need to do to test this? Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 22, 2014 Share Posted December 22, 2014 Assuming nothing crashes when you select a few orders for printing and click "Go", you next wait a bit (to give GA headquarters some time to log the data) then check your GA account. If you have a utility for your browser that tracks incoming and outgoing traffic, you may be able to spot if and when the javascript sends the data. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 22, 2014 Author Share Posted December 22, 2014 I tried a test order and used Firebug NET to try to see traffic. I didn't see anything that looked like traffic to Google. What should I look for? Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 22, 2014 Share Posted December 22, 2014 Knowing that the storefront will send a 'pageview' notice to GA when someone looks at a product, try to spot the traffic on a View Product page. The javascript on the admin page to print should cause a similar line of traffic. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 22, 2014 Author Share Posted December 22, 2014 I'm assuming GET jquery.min.js with a Request Header to ajax.googleapis.com is it? Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 22, 2014 Share Posted December 22, 2014 No. There should be a GET request to www.google-analytics.com/analytics.js, followed by another line of traffic to google-analytics.com. I now see a flaw in the edits to orders.print.php. There should be a set of data to send for each order, which means the code copied into it as instructed in post #4 needs to be inside the {foreach}. Otherwise, only the last order to be printed will have a notification sent to GA. I will have some edits soon. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 22, 2014 Author Share Posted December 22, 2014 I printed the order from the Order Summary page of a single order, as my usual practice. Is your solution dependent on printing from the page with ALL the orders listed? Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 22, 2014 Share Posted December 22, 2014 Where I said this: In the admin template orders.print.php, create a new blank line just above </body></html>. Move the copied code just above this: {/foreach} {/if} </body> </html> ( I have changed the instruction in post #4.) I believe orders.print.php is used whether you have an order be printed from that order's Order Summary screen, or from checked orders on the Orders List. Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 22, 2014 Share Posted December 22, 2014 As for the copied code itself, now that we need to have a possible situation of several orders to print, we need to make sure the GA code reflects this possibility. So, there is more to figure out. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 22, 2014 Author Share Posted December 22, 2014 I moved the edit in orders.print.php, so it's within {foreach}. I also tried to find the Google link on a storefront product page with Firebug NET, but I didn't see anything with an analytics.js, even though I have traffic info on Analytics. Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 22, 2014 Share Posted December 22, 2014 In the admin template file orders.print.php, make this change: Was new code added just above: {/foreach} {/if} </body> </html> Now this code in its place: {* NEW *} {if $ANALYTICS} <script> {literal} ga('require', 'ecommerce', 'ecommerce.js'); ga('ecommerce:addTransaction', { 'id': '{/literal}{$order.GA_SUM.cart_order_id}{literal}', 'affiliation': '{/literal}{$order.GA_SUM.store_name}{literal}', 'revenue': '{/literal}{$order.GA_SUM.total}{literal}', 'shipping': '{/literal}{$order.GA_SUM.shipping}{literal}', 'tax': '{/literal}{$order.GA_SUM.total_tax}{literal}' }); {/literal} {foreach from=$order.GA_ITEMS item=item} {literal} ga('ecommerce:addItem', { 'id': '{/literal}{$order.GA_SUM.cart_order_id}{literal}', 'name': '{/literal}{$item.name}{literal}', 'sku': '{/literal}{$item.product_code}{literal}', 'category': '{/literal}{if isset($item.options)}{foreach from=$item.options item=option}{$option} {/foreach}{/if}{literal}', 'price': '{/literal}{$item.price}{literal}', 'quantity': '{/literal}{$item.quantity}{literal}' }); {/literal} {/foreach} ga('ecommerce:send'); </script> {/if} {* NEW *} We need to be having the GA data be an element of each $order. In the file admin/sources/orders.index.inc.php: Recently added code: // Analytics if(in_array($summary['status'],array(2,3))) { $ga_id = $GLOBALS['config']->get('config', 'google_analytics'); $ga_id = trim($ga_id); $GLOBALS['smarty']->assign('ANALYTICS', !empty($ga_id) ? $ga_id : false); $GLOBALS['smarty']->assign('GA_ITEMS', $inventory); $vars['ga_sum'] = $summary; $vars['ga_sum']['country_iso'] = getCountryFormat($summary['country'], 'numcode', 'iso'); $vars['ga_sum']['google_id'] = $GLOBALS['config']->get('config', 'google_analytics'); $vars['ga_sum']['store_name'] = $GLOBALS['config']->get('config', 'store_name'); $GLOBALS['smarty']->assign('GA_SUM', $vars['ga_sum']); } Replace the above recently added code with the below code: /* NEW */ // Analytics if(in_array($summary['status'],array(2,3))) { $ga_id = $GLOBALS['config']->get('config', 'google_analytics'); $ga_id = trim($ga_id); $vars['ga_sum'] = $summary; $vars['ga_sum']['country_iso'] = getCountryFormat($summary['country'], 'numcode', 'iso'); $vars['ga_sum']['google_id'] = $GLOBALS['config']->get('config', 'google_analytics'); $vars['ga_sum']['store_name'] = $GLOBALS['config']->get('config', 'store_name'); $GLOBALS['smarty']->assign('ANALYTICS', !empty($ga_id) ? $ga_id : false); $summary['GA_ITEMS'] = $inventory; //$GLOBALS['smarty']->assign('GA_ITEMS', $inventory); $summary['GA_SUM'] = $vars['ga_sum']; // $GLOBALS['smarty']->assign('GA_SUM', $vars['ga_sum']); } /* NEW */ Here, the GA_ITEMS and GA_SUM data become an element of the respective order summary we are collecting the data for. Relevant parts of the data that I see on two GET requests on the Network tab of my browser: URL: http://www.google-analytics.com/r/collect QUERYSTRING (parts): t=transaction _s=1 dt=Order%20Invoice%20-%20141210-103146-3640 ti=141210-103146-3640 ta=Graystone%20Industries tr=%2414.67 ts=%246.66 tt=%241.02 URL: http://www.google-analytics.com/r/collect QUERYSTRING (parts): t=item _s=2 dt=Order%20Invoice%20-%20141210-103146-3640 tid=1 ti=141210-103146-3640 in=Test%20Product%20%234 ic=TESA34 ip=6.99 Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 23, 2014 Author Share Posted December 23, 2014 I really appreciate all your efforts to help and educate me, but even with your new code I'm not getting any analytics javascript on NET. I did find a conversion code that could be added that shows Conversions straight to Google Adwords. I don't know if it works yet, but it DOES show up in the Javascript tab of NET when I click the Print icon on Order Summary. So I know what an analytics link looks like in NET. I just installed a Google Tag Assistant in Chrome, and it may be a browser addin that is messing me up. Will try again tomorrow. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 23, 2014 Author Share Posted December 23, 2014 I had to use the GA code straight from Google to get the analytics.js to show in NET on the Blueprint customer product page. But it does work with the $ANALYTICS on the Kurouto skin for some reason. But I still don't get analytics.js showing on NET for the Print page. So I must be confused: 1. Copied the {if $ANALYTICS} section from main.php to above /head in orders.print.php2. Copied NEW section from #17 to just above {/foreach}3. Copied NEW section from #17 to orders.index.inc.php just above$label_fix = array('ship_method','ship_tracking','gateway'); Also, I noticed in your example of what the NET headers showed that you had other information besides the product link - I don't get price, etc., on the NET analytics.js Request Header for the product page.AcceptAccept-Encodinggzip, deflateAccept-Languageen-US,en;q=0.5Cache-Controlno-cacheConnectionkeep-aliveDNT1Hostwww.google-analytics.comPragmano-cacheRefererhttp://dirtybutter.com/plushcatalog/gund-heads-and-tales-lg-white-bear-red-green-plaid-bow.htmlUser-AgentMozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0I get the same kind of info on the Kurouto store as well.I won't have time to work on this anymore until company has gone home after Christmas. I hope you and your family have some wonderful time spent together. This can certainly wait!!! Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 23, 2014 Share Posted December 23, 2014 Send me orders.print.php and orders.index.inc.php in an email. Because this project is happening in the admin side of things, the skin you are using should not matter. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 23, 2014 Author Share Posted December 23, 2014 Thank you, Brian. It's been sent, with no need to be in a hurry to work on it!!! Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 25, 2014 Share Posted December 25, 2014 Referring to post #4 and #17, in file admin/sources/orders.index.inc.php, I asked you add code just above: Find near line 467: $label_fix = array('ship_method','ship_tracking','gateway'); foreach ($summary as $key => $value) { if (empty($value) && in_array($key,$label_fix)) $summary[$key] = ' '; } I see that there two occurrences of these lines of code: Near line 222, find: if (in_array($_GET['action'], array('add', 'edit'))) { then those lines are found about 76 lines after that. But it's the second occurrence that the code needs added: Near line 415, find: } else if (isset($_GET['print']) && !empty($_GET['print'])) { then those lines are found about 52 lines later. The line numbers refer to an unedited CC5214, so if your files have any other customization, be very attentive of where to add the code. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted December 26, 2014 Author Share Posted December 26, 2014 Thanks to your patient help, it appears to be working now. I'll know better in a few days. I AM glad I found the Chrome Tag Analyzer addin. That's very helpful. Quote Link to comment Share on other sites More sharing options...
harrisorganic Posted April 17, 2016 Share Posted April 17, 2016 Hi Brian and DB, It is over a year since this code was developed. Will this be applicable to CC6 and foundation skin? Quote Link to comment Share on other sites More sharing options...
bsmither Posted April 17, 2016 Share Posted April 17, 2016 It should be applicable to CC6. Also, keep in mind that adding this GA code to the admin's order print functionality does not depend on Foundation. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.