Page 1 of 1

Help! Google Analytics Reporting Wrong after upgrade

Posted: Thu Apr 09, 2009 7:03 am
by heinscott
Hopefully someone can help with this...
After upgrading to 7.02 last week, our Google Analytics started giving us double numbers for our sales. Does anyone know why this would be?? We haven't changed anything with regards to GA settings at all.
Please help. I'd love to be able to solve this problem before too much time goes by, and our data becomes completely worthless.
Thanks for the help.

Scott

Re: Help! Google Analytics Reporting Wrong after upgrade

Posted: Thu Apr 09, 2009 7:27 am
by heinscott
A bit more info....
I've looked at difference in code, and it look like from one install to the next, the GoogleAnalyticsWidget.aspx lost this piece of code:

Code: Select all

pageTracker._setAllowLinker(true);
		pageTracker._setDomainName("none");
Any idea if that could be the problem??

Thanks,

Scott

I've attached two pics from my Analytics, showing a particular order. All of our orders since the upgrade, it seems, are showing up the exact same way... The order value exactly twice what it should be, and the order details showing correctly.

Order Total for order in question:
OrderTotal.jpg
OrderDetails for order in question:
OrderDetail.jpg

Re: Help! Google Analytics Reporting Wrong after upgrade

Posted: Thu Apr 09, 2009 8:25 am
by heinscott
Okay another update to this drama...
I've looked at the source code of the rendered receipt page, and it looks as if the each item in the order is being submitted to google twice. Does this make any sense? Here is what I am seeing in the code:

Code: Select all

pageTracker._addTrans("36885","","16.16","0.18","12.99","Saline","MI","US");
pageTracker._addItem("36885","alube","Aladdin Magic Lube","Pool Repair","2.99","1");
pageTracker._addItem("36885","alube","Aladdin Magic Lube","Pool Repair","2.99","1");
pageTracker._trackTrans();
Any ideas?

Re: Help! Google Analytics Reporting Wrong after upgrade

Posted: Thu Apr 09, 2009 9:39 am
by heinscott

Code: Select all

private void RegisterTransactionScript()
    {
        string scriptKey = "GoogleAnalyticsTrans:" + this.UniqueID;
        if (!Page.ClientScript.IsStartupScriptRegistered(scriptKey))
        {
            LSDecimal shipping = 0;
            LSDecimal taxes = 0;
            LSDecimal total = 0;
            foreach (OrderItem item in _Order.Items)
            {
                LSDecimal extendedPrice = item.ExtendedPrice;
                switch (item.OrderItemType)
                {
                    case OrderItemType.Shipping:
                    case OrderItemType.Handling:
                        shipping += extendedPrice;
                        break;
                    case OrderItemType.Tax:
                        taxes += extendedPrice;
                        break;
                    default:
                        break;
                }
                total += item.ExtendedPrice;
            }
	        
			string transLine = "\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\"";
			transLine = string.Format(transLine, _Order.OrderId, "", string.Format("{0:F2}", total), string.Format("{0:F2}", taxes), string.Format("{0:F2}", shipping), _Order.BillToCity, _Order.BillToProvince, _Order.BillToCountryCode);
            
            string scriptBlock =
               @"<script language=""JavaScript"">
				<!--
					pageTracker._addTrans(" + transLine + ");";
            
            string itemLine = "\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\"";
            foreach (OrderItem item in _Order.Items)
            {
                switch (item.OrderItemType)
                {
                    case OrderItemType.Product:
                        itemLine = string.Format(itemLine, _Order.OrderId, item.Sku, item.Name, GetItemCategory(item), string.Format("{0:F2}", item.Price), item.Quantity);
                        scriptBlock += @"
							pageTracker._addItem(" + itemLine + ");";
                        break;
                }
            }
            scriptBlock +=
               @"
				  pageTracker._trackTrans();                   
               // -->
               </script>";

            Page.ClientScript.RegisterStartupScript(this.GetType(), scriptKey, scriptBlock);
        }
    }
Mazhar... Does this seem right to you? This is RegisterTransactionScript method in GoogleAnalyticsWidget. As you can see, itemLine is initialized as a string of placeholders, but then in the forloop, it is being overwritten with a value that uses itself. Now, this would work okay for only 1 iteration, but, will not work for the second time through. I went back and looked at all of my old data, too, and found that no order showed more than one item on the order.

I fixed on my side with:

Code: Select all

string itemLineForm = "\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\"";
            foreach (OrderItem item in _Order.Items)
            {
                switch (item.OrderItemType)
                {
                    case OrderItemType.Product:
                        string itemLine = string.Format(itemLineForm, _Order.OrderId, item.Sku, item.Name, GetItemCategory(item), string.Format("{0:F2}", item.Price), item.Quantity);
                        scriptBlock += @"
							pageTracker._addItem(" + itemLine + ");";
                        break;
                }
            }
Not sure if this will fix the double order total amounts, but, at least it will start recording the item data correctly.

Re: Help! Google Analytics Reporting Wrong after upgrade

Posted: Thu Apr 09, 2009 9:56 am
by mazhar
Hmm first make sure that you are using only single instance of Google Analytics control on your page. For example one instance could be in footer and one may be in contents or some where else.

Re: Help! Google Analytics Reporting Wrong after upgrade

Posted: Thu Apr 09, 2009 11:15 am
by heinscott
No, I've checked for that... There is only one control on the page. The values are just being figured wrong. When I look at the source, the total ammount line being send to google is double. I have a feeling it has something to do with how kit pricing is figured. Most of the items in our store are in the form of kits.... Has anything with kitting changed since the upgrade? Like perhaps the "Price" for orderItems? I'm still at a loss here.

Re: Help! Google Analytics Reporting Wrong after upgrade

Posted: Thu Apr 09, 2009 12:24 pm
by heinscott
Okay...

It appears that the problem is occuring because around line 189 on the ReceiptPage.ascx.cs

Code: Select all

if (index > -1) _Order.Items[index].Price += (item.ExtendedPrice / _Order.Items[index].Quantity);
It appears that the price of a parent order item is being modified temporarily to accomodate (I assume) some kind of kit grouping on the page. As a result, though, when the GoogleAnalyticsWidget tries to use _Order.Items, prices will be added into the order total twice.

Not sure what the best fix for this bug would be. I fixed on mine by setting the ordertotal equal to _Order.TotalCharges, and skipped added an item to the list when it has a parent item.

Is there a better way to go about fixing this??

Re: Help! Google Analytics Reporting Wrong after upgrade

Posted: Fri Apr 10, 2009 7:15 am
by heinscott
So, should this be reported as a bug then?

Scott

Re: Help! Google Analytics Reporting Wrong after upgrade

Posted: Fri Apr 10, 2009 7:39 am
by sohaib
Thanks scott! I think you have discovered (and fixed) a couple of bugs.

These will be logged into bugzilla and will be fixed in 7.3.