Google Analytics Integration - SureCart

No results found. Try again with different words?

Search must be at least 3 characters.

Google Analytics Integration

You can integrate SureCart purchases with Google Analytics. To do this, you will want to add a bit of custom code to your site. The easiest way to do this is to use a free code snippets plugin, though you can do this in your theme or with a separate plugin too.

This tutorial assumes that you’ve done the following:

Our checkout component emits an event called scOrderPaid, which happens when a checkout is paid. This lets you listen for the event, and look at the checkout data to send to Google Analytics. An easy way to do this is to add this to your site’s footer. Here’s an example:

<?php
add_action(
    'wp_footer',
    function() {  ?>
        <script>
            document.querySelector('sc-checkout').addEventListener('scOrderPaid', function(e) {
                const checkout = e.detail;
                if( checkout && checkout.amount_due ) {
                    gtag("event", "purchase", {
                        value: checkout.amount_due / 100,
                        currency: (checkout.currency || '').toUpperCase(),
                    });
                }
            });
        </script>
        <?php
    }
);

Was this article helpful?


Did not find a solution? We are here to help you succeed.

Try SureCart today

And experience the better way to sell on your website

30-Day money-back guarantee
24/7 world class support team
Safe & secure online payment

Remind me about SureCart HUGE Black Friday Sale

Scroll to Top