Google Conversion Tracking (NOP 4.2)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
Is there a built-in method for doing Google conversion tracking in NC?
The Google plug in, while it does tracking, has no method of inserting the dollar amount of the final sale, so we've only been able to put in $1 default, but, unfortunately, Google's new Smart Shopping system doesn't work properly with generic amounts of $1 - it needs the ACTUAL DOLLAR AMOUNT.

I was going to  hard code the tracking code into the system, but was hoping someone else had figured this out (since every time I make a tiny change in NC source code, it often breaks something else and ends up taking days to troubleshoot :(

Here's the snippet from Google - Note the 'value' portion needs the final price (instead of just 1.0)

<!-- Event snippet for Website Purchases conversion page -->
<script>
  gtag('event', 'conversion', {
      'send_to': 'AW-000000000/xxXXXX-xxXxXXX-XxXXX',
      'value': 1.0,
      'currency': 'USD',
      'transaction_id': ''
  });
</script>


If you try to inject it with another script after the page is delivered to the browser, their script won't register/work.  The only way is the generate the script on the fly on the final checkout complete page with a token to replace the value.  If anyone has done this before, please let me know.
3 years ago
Got it figured out.  Changed the CheckoutCompletedModel and added OrderSubtotal to the class
using Nop.Web.Framework.Models;

namespace Nop.Web.Models.Checkout
{
    public partial class CheckoutCompletedModel : BaseNopModel
    {
        public int OrderId { get; set; }
        public string CustomOrderNumber { get; set; }
        public bool OnePageCheckoutEnabled { get; set; }
        public decimal OrderSubtotal { get; set; }
    }
}


then, in the checkoutmodelfactory, I changed "PrepareCheckoutCompletedModel" to look like so:

        public virtual CheckoutCompletedModel PrepareCheckoutCompletedModel(Order order)
        {
            if (order == null)
                throw new ArgumentNullException(nameof(order));

            var model = new CheckoutCompletedModel
            {
                OrderId = order.Id,
                OnePageCheckoutEnabled = _orderSettings.OnePageCheckoutEnabled,
                CustomOrderNumber = order.CustomOrderNumber,
                OrderSubtotal = order.OrderSubtotalExclTax
            };

            return model;
        }


Finally, on the Completed.cshtml page, I put in the script at the bottom
<script>
    gtag('event', 'conversion', {
        'send_to': 'AW-XXXXXXXXXXXXXXXXXXXXXXXX-XXXXX',
        'value': @Model.OrderSubtotal.ToString("N2"),
        'currency': 'USD',
        'transaction_id': ''
    });
</script>


Works like a charm
3 years ago
The Google Analytics plugin is available out of the box. Just use it along with eCommerce functionality enabled
3 years ago
Unfortunately, that plugin has never worked for me and Google's "troubleshooter" guy told me to use the Google Tag Manager instead, so I implemented it and, while it works, it does not track conversions (since there's no way to tell Google what the order total is - without somehow injecting the total into the final checkout page script).  
Then, I just discovered that my "solution" does not work, after all and getting "(index):351 Uncaught ReferenceError: gtag is not defined". Apparently, that script is ALSO not compatible with GTM, so back to square one.   I hate Google, sometimes.
3 years ago
If someone made a Google Tag Manager plugin for NopCommerce, I'd gladly pay good money for it.  I'm at wit's end and Google continues to punish sites that don't implement their scripts correctly!
2 years ago
Any luck with this?

Anyone got it working with the standard GA plugin?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.