NOP 4.0 Google Analytics - problem with conversions? Analytics Widget problem/delete {ecommerce}?

1 2 >
Posted: April 13, 2018 at 12:39 PM Quote #203161
I described my problem here: https://www.nopcommerce.com/boards/t/51545/nop-40-problem-with-analytics-and-conversions.aspx


in short... After upgrade 3.7 > NOP4, our GA(Google Analytics) stop working and show 0 transactions...

I saw ths few day ago, and i was thinking it's problem because i have unchecked Ecommerce checkbox (don't know is this in 3.7 also), and was think it's this...

Today I check again panel and i see few problem:
1. Conversion are only from "direct" source. All other source have 0 conversions.
2, Wrong summary. For example Nopcommerce show 100 orders first day and 100 a second day, but in GA we have 180 (first day) and 40 orders (next day)...

I check code in demo admin panel and maybe i found bug http://admin-demo.nopcommerce.com/Admin/WidgetsGoogleAnalytics/Configure

Your analytics code before we click anything is:
<!-- Google code for Analytics tracking -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{GOOGLEID}']);
_gaq.push(['_trackPageview']);
{ECOMMERCE}
(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>

BUT if we click anything (one button from pre-configure Google Analytics / Universal Analytics) our script code are changed and {ECOMMERCE} line missing?

PRECONFIGURE GOOGLE ANALYTICS code
<!-- Google code for Analytics tracking -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{GOOGLEID}']);
_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>

Preconfigure Universal Analytics
<!-- Google code for Analytics tracking -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{GOOGLEID}']);
_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>

If we don't perceive/saw this before click save... {ecommerce} is deleted, and we can't move to see "first code".


My code after clicks look like below: I don't have {ecommerce} line, maybe that's why it's stoped work?

<!-- Google code for Analytics tracking -->
<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', '{GOOGLEID}', 'auto');
ga('send', 'pageview');
</script>
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Hmmm...
Posted: April 14, 2018 at 4:40 AM Quote #203171
Well maybe it's to early, but nothing change, and still conversion is only from direct source :(
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Hmmm...
Posted: April 14, 2018 at 7:13 AM Quote #203176
1. nopCommerce version 4.0
2. Expected behavior
Show conversions, "real" statistics.

3. Actual behavior
Show only conversion from direct source. All connect accounts (adwords) show 0 transactions. All referals / organic source show 0 conversions .

4. Steps to reproduce the problem

Don't know. We only make update from 3.7 > 4.0 and conversions stop work :/

5. Any private modifications you made to your nopCommerce

We upgrade 3.7 - 4.0 and install NopTemplates ELement Theme. Also we have Google Tag Manager from Foxnet (but install few day after make upgrade... and don't add there Analytics code).

We have changed "Completed" page. but we only change text there.

I compare Nopcommerce demo and our completed page, and before end of body tag, we have:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'GOOGLE-ID']);
_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>


Nopcommerce code
<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', 'XXXXXXX', 'nopcommerce.com');
         ga('send', 'pageview');
    </script>


We also have after <body>

<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = XXXXXX;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
var google_user_id = '1';
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/XXXXXXXXXX/?value=0&amp;guid=ON&amp;script=0&amp;userId=1"/>
</div>


Hmm... any ideas?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Hmmm...
Posted: April 16, 2018 at 1:15 PM Quote #203273
Hello,

So we just ran into this same problem and are in the process working through it, but I think this is a bug in the plugin that handles Google Analytics for Nop.

The way Google tracks conversions is using the gclid query string that gets appended to the landing page the customer enters. This id is then saved to a cookie.

Then, when a customer completes check out, the analytics tag uses that cookie to associate the transaction to the conversion.

However, it looks like in the Nop 4.0 code, the plugin is sending the transaction event from server side code instead of the client. So while it creates the transaction successfully in analytics, since it's sending from the server it doesn't associate with the the client's cookie that stores the gclid and shows up as a direct/none source.

I was able to edit our confirmation page to pull back the order information and implement the analytics transaction code directly on the page and now it seems to be working correctly for us.
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: April 23, 2018 at 3:43 AM Quote #203545
Oh it's not only me. Uff...:) i still fighting with this. Maybe i use FoxNetTrackingCode... and disable Nopcommerce Team plugin. I try reinstall but it's nothing change.

I check this today again.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Hmmm...
Posted: April 23, 2018 at 8:12 AM Quote #203554
If it helps, here's what steps I took to resolve it:

1. Disable ecommerce tracking in the Nop plugin.
2. Edit the checkout completed page in your theme, adding the following...

This gets the order details:

var _orderService = EngineContext.Current.Resolve<IOrderService>();
var orderModelFactory = EngineContext.Current.Resolve<IOrderModelFactory>();

var order = _orderService.GetOrderById(Model.OrderId);
var orderDetails = orderModelFactory.PrepareOrderDetailsModel(order);


And then generate the transaction that analytics requires. Note that we only accept US dollars as currency so I'm hard-coding the replacement of those values in the totals.

@* Google ecomm transaction *@
<script>
    ga('require', 'ecommerce');

    ga('ecommerce:addTransaction', {
        'id': '@orderDetails.Id',
        'affiliation': 'SITENAME',
        'revenue': '@orderDetails.OrderTotal.Replace("$", "").Replace(",", "")',
        'shipping': '@orderDetails.OrderShipping.Replace("$", "").Replace(",", "")',
        'tax': '@orderDetails.Tax.Replace("$", "").Replace(",", "")'
    });

    @foreach (var item in orderDetails.Items)
    {
        <text>
            ga('ecommerce:addItem', {
                'id': '@orderDetails.Id',
                'name': '@item.ProductName',
                'sku': '@item.Sku',
                'price': '@item.UnitPrice.Replace("$", "").Replace(",", "")',
                'quantity': '@item.Quantity'
            });
        </text>
    }

    ga('ecommerce:send');
</script>
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: April 24, 2018 at 9:56 AM Quote #203600
Hi if i add this by google tag manager, this should be ok? I should put this into <head></head>?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Hmmm...
Posted: April 24, 2018 at 11:16 AM Quote #203604
Zyje_sobie wrote:
Hi if i add this by google tag manager, this should be ok? I should put this into <head></head>?


No, this would be on your confirmation page. On our site, it's in the theme's folder, then /Views/Checkout/Completed.cshtml.

Then the first part is C# code that grabs the order, so it would need to be contained in a code block (the @{}) anywhere before the javscript code, like so:

@{
  var _orderService = EngineContext.Current.Resolve<IOrderService>();
  var orderModelFactory = EngineContext.Current.Resolve<IOrderModelFactory>();

  var order = _orderService.GetOrderById(Model.OrderId);
  var orderDetails = orderModelFactory.PrepareOrderDetailsModel(order);
}


The other part of the code can be wherever as long as it's after this first part, and doesn't need to be wrapped in a code block... but still needs to be on the cshtml page directly. I have it at the bottom of our page.
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: June 16, 2018 at 7:52 AM Quote #205847
Hi! i come back with problem ;) We don't test your solution (we start if nobody answer to us :(.

But i found today this topic: https://www.nopcommerce.com/boards/t/41631/e-commerce-tracking-is-not-working-in-nopcommerce-340.aspx

And there is something like:


1. Tracking code with {ECOMMERCE} line:

<!-- Google code for Analytics tracking -->
<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', '{GOOGLEID}', 'auto');
ga('send', 'pageview');
{ECOMMERCE}
</script>



2.Tracking code for {ECOMMERCE} part, with {DETAILS} line:

ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {
'id': '{ORDERID}',
'affiliation': '{SITE}',
'revenue': '{TOTAL}',
'shipping': '{SHIP}',
'tax': '{TAX}'
});
{DETAILS}
ga('ecommerce:send');


3.Tracking code for {DETAILS} part:


ga('ecommerce:addItem', {
'id': '{ORDERID}',
'name': '{PRODUCTNAME}',
'sku': '{PRODUCTSKU}',
'category': '{CATEGORYNAME}',
'price': '{UNITPRICE}',
'quantity': '{QUANTITY}'
});


I remember in 3.7 we have a similiar 3 fields to add code. Now we have only: Tracking code with {ECOMMERCE} line

Is point 2 and 3 are implented in core and hidden in NOP 4.0 or maybe something gone wrong when we install plugin and that's why we see only one field to add code in ecommerce line? Maybe somebody from Nopcommerce team can confirm it's ok? and this should work?

It's really problematic make any campaign without data about conversions :(
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Hmmm...
Posted: June 20, 2018 at 1:46 PM Quote #206036
In the 4.0 version of the plugin, the previous way the plugin generated the ecommerce tracking no longer applies since it's actually removing the "{ECOMMERCE}" part in the code completely.

The method we ended up using was to basically ignore the ecommerce tracking in the plugin itself and generate our own code for it, basically using the way the older versions of the plugin handled it.

This seems like a bug with the plugin though, so either the Nop team would need to update it or you would have to update your order confirmation page and include the code the old plugin would generate (the parts from step 2 and 3 in your post).

For reference, it looks like the Nop team does have a bug for this: https://github.com/nopSolutions/nopCommerce/issues/2993
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
1 2 >
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.
eCommerce CONFERENCE 2018
Learn more