Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi All,
Does anyone have a Razor sample for generating Google analytics e-commerce tracking sample they would care to share?
If not, I will create one :-)
Thanks,
Jeavon
Download the starter kit. See in the Scripts (Razor)/tea-commerce/EcommerceTracking.cshtml
That should be it :)
Awesome, I only had v3.0 of the stater kit and this didn't exist.
I would recommend one tweak though:
Update
string sku = orderLine.ProductIdentifier;
to
string sku = orderLine.Sku;
Thanks!! Corrected :)
Here is the optimized and refactored code:
@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(['_set', 'currencyCode', '@TC.GetCurrency(storeId, finalizedOrder.CurrencyId).IsoCode']);_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.WithVatFormattedWithoutSymbol', // price '@orderLine.Quantity' // quantity]);</text> }_gaq.push(['_trackTrans']);</script>}
Even better! Thanks
Just discovered that the currencyCode need to be set after the addTrans otherwise it doesn't work, here is revised version
@{ 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.WithVatFormattedWithoutSymbol', // price '@orderLine.Quantity' // quantity ]);</text> } _gaq.push(['_set', 'currencyCode', '@TC.GetCurrency(storeId, finalizedOrder.CurrencyId).IsoCode']); _gaq.push(['_trackTrans']); </script> }
Thanks for sharing! Have updated the starter kit - so in next release it will be fixed :)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Razor TeaCommerce Google analytics e-commerce Tracking Sample
Hi All,
Does anyone have a Razor sample for generating Google analytics e-commerce tracking sample they would care to share?
If not, I will create one :-)
Thanks,
Jeavon
Download the starter kit. See in the Scripts (Razor)/tea-commerce/EcommerceTracking.cshtml
That should be it :)
Awesome, I only had v3.0 of the stater kit and this didn't exist.
I would recommend one tweak though:
Update
to
Thanks!! Corrected :)
Here is the optimized and refactored code:
Even better! Thanks
Just discovered that the currencyCode need to be set after the addTrans otherwise it doesn't work, here is revised version
Thanks,
Jeavon
Thanks for sharing! Have updated the starter kit - so in next release it will be fixed :)
is working on a reply...