Prices tracked in Google Analytics doesn't seem to be right
Hi guys..
I have setup a webshop which have be active for some months now and tracking the orders in Google Analytics.. but I noticed that it seems that the prices from the checkout and send to Google not is correct.. perhaps Google need the price in a specific format?
E.g. there are two products: A product Surface with a price of 2316 DKK (2895 DKK incl. VAT) and a product called Style with a price of 2876 DKK (3595 DKK incl. VAT).
This is what is tracked in Google Analytics:
This line in cart/google-ecommerce-tracking.cshtml might format the price so Google handle thousand separator as decimal separator and round the price?
The values for the price and total parameters do not respect any currency formatting. For both parameters, the first instance of either a comma or a period indicates a fractional value. So, for example, if you provide 1,996.00 as the value for the total parameter, it is recorded as 1.996, not as $1,996.00. Because the value is not affiliated with any currency, your ecommerce software must handle any currency conversion before you pass the data to Analytics.
How is WithVatFormattedWithoutSymbol formatting the price in this case? Like a value of 2.895 from above? and seem to be handled as a price in the English price format..
The price is formatted with the culture that is specified at the currency in Tea Commerce. If you need to format the price with a specific culture, there is a Razor method for that in the API. So that should do the trick. Please send the new code that works - if you get it working.
I started changing @orderLine.UnitPrice.WithVatFormattedWithoutSymbol to @orderLine.UnitPrice.Value in cart/google-ecommerce-tracking.cshtml .. and now a new order has been completed, so I see if it makes a difference.
@using umbraco.MacroEngines
@using TeaCommerce.Umbraco.Web
@using TeaCommerce.Api.Models
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
long storeId = long.Parse(Model._store);
Order finalizedOrder = TC.GetCurrentFinalizedOrder(storeId);
<script type="text/javascript">
_gaq.push(['_addTrans',
'@finalizedOrder.OrderNumber', // transaction ID - required
'@TC.GetStore(storeId).Name', // affiliation or store name
'@finalizedOrder.TotalPrice.WithVatFormattedWithoutSymbol', // total - required
'@finalizedOrder.TotalPrice.VatFormattedWithoutSymbol', // tax
'@finalizedOrder.ShipmentInformation.TotalPrice.WithVatFormattedWithoutSymbol', // shipping
'@finalizedOrder.Properties["city"]', // city
'@(finalizedOrder.PaymentInformation.CountryRegionId != null ? TC.GetCountryRegion(storeId, finalizedOrder.PaymentInformation.CountryRegionId.Value).Name : "")', // state or province
'@TC.GetCountry(storeId, finalizedOrder.PaymentInformation.CountryId).Name' // country
]);
@foreach ( OrderLine orderLine in finalizedOrder.OrderLines ) {
<text>_gaq.push(['_addItem',
'@finalizedOrder.OrderNumber', // transaction ID
'@orderLine.Sku', // SKU
'@orderLine.Name', // product name
'@Library.NodeById( orderLine.ProductIdentifier ).AncestorOrSelf( "ProductCategory" ).Name', // category
'@orderLine.UnitPrice.Value', // WithVatFormattedWithoutSymbol price
'@orderLine.Quantity' // quantity
]);</text>
}
_gaq.push(['_set', 'currencyCode', '@TC.GetCurrency(storeId, finalizedOrder.CurrencyId).IsoCode']);
_gaq.push(['_trackTrans']);
</script>
}
The data tracked for a previous order before the changing:
and this is how it looks now:
It seems more right.. however it's the price excl. VAT.
I think it would be better to track the prices the customers pay and therefore use WithVat property instead of Value. But without formatting of the price.. furthermore it should also be changed for the other prices e.g. total price. It seems to work in Danish now :)
After making some small changes in the razor file cart/google-ecommerce-tracking.cshtml and look at the new data Google is tracking, this code seems to be more correct.
@using umbraco.MacroEngines
@using TeaCommerce.Umbraco.Web
@using TeaCommerce.Api.Models
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
long storeId = long.Parse(Model._store);
Order finalizedOrder = TC.GetCurrentFinalizedOrder(storeId);
<script type="text/javascript">
_gaq.push(['_addTrans',
'@finalizedOrder.OrderNumber', // transaction ID - required
'@TC.GetStore(storeId).Name', // affiliation or store name
'@finalizedOrder.TotalPrice.WithVat', // WithVatFormattedWithoutSymbol total - required
'@finalizedOrder.TotalPrice.Vat', // VatFormattedWithoutSymbol tax
'@finalizedOrder.ShipmentInformation.TotalPrice.WithVat', // WithVatFormattedWithoutSymbol shipping
'@finalizedOrder.Properties["city"]', // city
'@(finalizedOrder.PaymentInformation.CountryRegionId != null ? TC.GetCountryRegion(storeId, finalizedOrder.PaymentInformation.CountryRegionId.Value).Name : "")', // state or province
'@TC.GetCountry(storeId, finalizedOrder.PaymentInformation.CountryId).Name' // country
]);
@foreach ( OrderLine orderLine in finalizedOrder.OrderLines ) {
<text>_gaq.push(['_addItem',
'@finalizedOrder.OrderNumber', // transaction ID
'@orderLine.Sku', // SKU
'@orderLine.Name', // product name
'@Library.NodeById( orderLine.ProductIdentifier ).AncestorOrSelf( "ProductCategory" ).Name', // category
'@orderLine.UnitPrice.WithVat', // WithVatFormattedWithoutSymbol price
'@orderLine.Quantity' // quantity
]);</text>
}
_gaq.push(['_set', 'currencyCode', '@TC.GetCurrency(storeId, finalizedOrder.CurrencyId).IsoCode']);
_gaq.push(['_trackTrans']);
</script>
}
It shows me the right prices in Google Analytics now:
Your changes looks better yes. I have added the changes to the online version of the starter kit and tested it there and it looks like it works better that way.Problem was with some non english sites using komma instead og dot as decimal separator.
It will be released with the next version of the starter kit.
Yes, according to the documentation of Google Analytics, it seems that the price not should be formatted and sended af English formatted price.. then there are an additional parameter to handle the currency..
The latest data tracked from the shop seems to be right :)
You can actually place it anywhere you want. It will only trigger when there's a current finlized order.
I have tested the script and have arrived at the code below. It's the most correct way to do it and orders flows into google analytics with no problems:
@using System.Globalization
@using TeaCommerce.Umbraco.Web
@using TeaCommerce.Api.Models
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
long storeId = long.Parse( Model._store );
Order finalizedOrder = TC.GetCurrentFinalizedOrder( storeId );
if ( finalizedOrder != null ) {
<script type="text/javascript">
_gaq.push(['_addTrans',
'@finalizedOrder.OrderNumber', // transaction ID - required
'@TC.GetStore( storeId ).Name', // affiliation or store name
'@finalizedOrder.TotalPrice.WithVat.ToString("0.##", CultureInfo.InvariantCulture)', // total - required
'@(finalizedOrder.PaymentInformation.CountryRegionId != null ? TC.GetCountryRegion( storeId, finalizedOrder.PaymentInformation.CountryRegionId.Value ).Name : "")', // state or province
'@TC.GetCountry( storeId, finalizedOrder.PaymentInformation.CountryId ).Name' // country
]);
@foreach ( OrderLine orderLine in finalizedOrder.OrderLines ) {
Prices tracked in Google Analytics doesn't seem to be right
Hi guys..
I have setup a webshop which have be active for some months now and tracking the orders in Google Analytics.. but I noticed that it seems that the prices from the checkout and send to Google not is correct.. perhaps Google need the price in a specific format?
E.g. there are two products: A product Surface with a price of 2316 DKK (2895 DKK incl. VAT) and a product called Style with a price of 2876 DKK (3595 DKK incl. VAT).
This is what is tracked in Google Analytics:
This line in cart/google-ecommerce-tracking.cshtml might format the price so Google handle thousand separator as decimal separator and round the price?
'@orderLine.UnitPrice.WithVatFormattedWithoutSymbol', // price
It seems that e.g. the product price for Surface is handled as 2,895 DKK and then rounded to 2,90 DKK?
/Bjarne
Perhaps it has something to do with this?
price
andtotal
parameters do not respect any currency formatting.For both parameters, the first instance of either a comma or a period indicates a fractional value. So, for example, if you provide
1,996.00
as the value for thetotal
parameter, it is recorded as1.996
, not as $1,996.00. Because the value is not affiliated with any currency, your ecommerce software must handle any currency conversion before you pass the data to Analytics.https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce
How is WithVatFormattedWithoutSymbol formatting the price in this case? Like a value of 2.895 from above? and seem to be handled as a price in the English price format..
The price is formatted with the culture that is specified at the currency in Tea Commerce. If you need to format the price with a specific culture, there is a Razor method for that in the API. So that should do the trick. Please send the new code that works - if you get it working.
Kind regards
Anders
Hi Anders
I started changing @orderLine.UnitPrice.WithVatFormattedWithoutSymbol to @orderLine.UnitPrice.Value in cart/google-ecommerce-tracking.cshtml .. and now a new order has been completed, so I see if it makes a difference.
The data tracked for a previous order before the changing:
and this is how it looks now:
It seems more right.. however it's the price excl. VAT.
I think it would be better to track the prices the customers pay and therefore use WithVat property instead of Value. But without formatting of the price..
furthermore it should also be changed for the other prices e.g. total price. It seems to work in Danish now :)
/Bjarne
Hi Anders
After making some small changes in the razor file cart/google-ecommerce-tracking.cshtml and look at the new data Google is tracking, this code seems to be more correct.
It shows me the right prices in Google Analytics now:
/Bjarne
Hi Bjarne,
Your changes looks better yes. I have added the changes to the online version of the starter kit and tested it there and it looks like it works better that way.Problem was with some non english sites using komma instead og dot as decimal separator.
It will be released with the next version of the starter kit.
Thanks for your input
/Rune
Hi Rune..
Yes, according to the documentation of Google Analytics, it seems that the price not should be formatted and sended af English formatted price.. then there are an additional parameter to handle the currency..
The latest data tracked from the shop seems to be right :)
/Bjarne
Is the correct place to put this macro in the confirmation page or what?
You can actually place it anywhere you want. It will only trigger when there's a current finlized order.
I have tested the script and have arrived at the code below. It's the most correct way to do it and orders flows into google analytics with no problems:
@using System.Globalization
@using TeaCommerce.Umbraco.Web
@using TeaCommerce.Api.Models
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
long storeId = long.Parse( Model._store );
Order finalizedOrder = TC.GetCurrentFinalizedOrder( storeId );
if ( finalizedOrder != null ) {
<script type="text/javascript">
_gaq.push(['_addTrans',
'@finalizedOrder.OrderNumber', // transaction ID - required
'@TC.GetStore( storeId ).Name', // affiliation or store name
'@finalizedOrder.TotalPrice.WithVat.ToString("0.##", CultureInfo.InvariantCulture)', // total - required
'@finalizedOrder.TotalPrice.Vat.ToString("0.##", CultureInfo.InvariantCulture))', // tax
'@finalizedOrder.ShipmentInformation.TotalPrice.WithVat.ToString("0.##", CultureInfo.InvariantCulture))', // shipping
'@finalizedOrder.Properties[ "city" ]', // city
'@(finalizedOrder.PaymentInformation.CountryRegionId != null ? TC.GetCountryRegion( storeId, finalizedOrder.PaymentInformation.CountryRegionId.Value ).Name : "")', // state or province
'@TC.GetCountry( storeId, finalizedOrder.PaymentInformation.CountryId ).Name' // country
]);
@foreach ( OrderLine orderLine in finalizedOrder.OrderLines ) {
<text>_gaq.push(['_addItem',
'@finalizedOrder.OrderNumber', // transaction ID
'@orderLine.Sku', // SKU
'@orderLine.Name', // product name
'@Library.NodeById( orderLine.ProductIdentifier ).AncestorOrSelf( "ProductCategory" ).Name', // category
'@orderLine.UnitPrice.WithVat.ToString("0.##", CultureInfo.InvariantCulture))', // price
'@orderLine.Quantity' // quantity
]);</text>
}
_gaq.push(['_set', 'currencyCode', '@TC.GetCurrency( storeId, finalizedOrder.CurrencyId ).IsoCode']);
_gaq.push(['_trackTrans']);
</script>
}
}
is working on a reply...