Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 06, 2013 @ 12:42
    Jeavon Leopold
    0

    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

  • Anders Burla Johansen 2560 posts 8256 karma points
    Jun 06, 2013 @ 13:06
    Anders Burla Johansen
    100

    Download the starter kit. See in the Scripts (Razor)/tea-commerce/EcommerceTracking.cshtml

    That should be it :)

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 06, 2013 @ 13:59
    Jeavon Leopold
    0

    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;

     

  • Anders Burla Johansen 2560 posts 8256 karma points
    Jun 06, 2013 @ 14:27
    Anders Burla Johansen
    0

    Thanks!! Corrected :)

  • Anders Burla Johansen 2560 posts 8256 karma points
    Jun 06, 2013 @ 15:00
    Anders Burla Johansen
    1

    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>
    }
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 06, 2013 @ 15:37
    Jeavon Leopold
    0

    Even better! Thanks

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 21, 2013 @ 12:18
    Jeavon Leopold
    0

    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,

    Jeavon

  • Anders Burla Johansen 2560 posts 8256 karma points
    Jun 21, 2013 @ 12:26
    Anders Burla Johansen
    0

    Thanks for sharing! Have updated the starter kit - so in next release it will be fixed :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies