New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content.receipt.php - google tracking needs updating #1858

Closed
Noodleyman opened this Issue Jan 17, 2018 · 7 comments

Comments

Projects
None yet
4 participants
@Noodleyman

Noodleyman commented Jan 17, 2018

content.receipt uses ga.js which is depreciated and replaced by analytics.js, thus needs to be updated with the latest standard in foundation.

https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce

@Noodleyman

This comment has been minimized.

Noodleyman commented Jan 23, 2018

to save you some time, just pull the old code and copy/paste below. tested and working on another site.

            {if $ANALYTICS}
                {literal}
                <!-- Google Analytics -->
                <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');
                    ga('require', 'ecommerce');   // Load the ecommerce plug-in.

                    ga('ecommerce:addTransaction', {
                        'id': '{/literal}{$GA_SUM.cart_order_id}{literal}',             // Transaction ID. Required
                        'affiliation': '{/literal}{$GA_SUM.store_name}{literal}',       // Affiliation or store name
                        'revenue': '{/literal}{$GA_SUM.total}{literal}',                // Grand Total
                        'shipping': '{/literal}{$GA_SUM.shipping}{literal}',            // Shipping
                        'tax': '{/literal}{$GA_SUM.total_tax}{literal}'                 // Tax
                    });

                    {/literal}
                    {foreach from=$GA_ITEMS item=item}
                    {literal}
                        ga('ecommerce:addItem', {
                            'id': '{/literal}{$GA_SUM.cart_order_id}{literal}',          // Transaction ID. Required
                            'name': '{/literal}{$item.name}{literal}',                   // Product name. Required
                            'sku': '{/literal}{$item.product_code}{literal}',            // SKU/code
                            //'category': 'Green Medium',                                // Category or variation
                            'price': '{/literal}{$item.price}{literal}',                 // Unit price
                            'quantity': '{/literal}{$item.quantity}{literal}'            // Quantity
                        });
                    {/literal}
                    {/foreach}
                    {literal}
                    ga('ecommerce:send');

                </script>
                <!-- End Google Analytics -->
                {/literal}
            {/if}
@havenswift-hosting

This comment has been minimized.

havenswift-hosting commented Jan 23, 2018

You have a couple of lines commented out in this code

//ga('send', 'pageview');

//'category': 'Green Medium',

@Noodleyman

This comment has been minimized.

Noodleyman commented Jan 23, 2018

yes, because category isn't supported by CubeCart yet, see:
#1859

and pageview isn't required, since it's already captured by the standard google tracking code already called. leaving it on this section causes duplicate page counts / errors.

@havenswift-hosting

This comment has been minimized.

havenswift-hosting commented Jan 23, 2018

Suggest then that Al deletes the first and changes second to

//'category': '',

Thanks for providing the code though - hopefully Al can implement using that and implement #1859 quickly as that will be needed as well

@bhsmither

This comment has been minimized.

Contributor

bhsmither commented Feb 8, 2018

Is it worth considering to extract this code out of the template, create a plugin for it, and have the plugin use the appropriate hook to load it into BODY_JS?

The plugin can be independently updated.

@havenswift-hosting

This comment has been minimized.

havenswift-hosting commented Feb 14, 2018

Is it worth considering to extract this code out of the template, create a plugin for it, and have the plugin use the appropriate hook to load it into BODY_JS? The plugin can be independently updated.

That sounds like a great idea

@abrookbanks abrookbanks self-assigned this Feb 19, 2018

@abrookbanks abrookbanks added this to the 6.1.14 milestone Feb 19, 2018

@abrookbanks

This comment has been minimized.

Member

abrookbanks commented Feb 19, 2018

Thanks for this guys. I formatted the code a bit less HTML comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment