Copied to clipboard

Flag this post as spam?

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


  • Palle Hansen 143 posts 396 karma points
    May 04, 2015 @ 08:39
    Palle Hansen
    0

    Google Tracking shows error

    Hi,
    I'm having some problem with the Google Tracking script in Teacommerce.
    It' gives me an error, when returning to the confirmation page.

    See below





    Line 12 is the problem it seems, and line 12 is this:
    '@finalizedOrder.OrderNumber',           // transaction ID - required

    The shop is working just fine, and all payments is good. 
    I can't seem to figure it out.

    Any body knows whats could med wrong?

    /Best
    Palle

  • Bjarne Fyrstenborg 1257 posts 3803 karma points MVP 6x c-trib
    May 04, 2015 @ 09:24
    Bjarne Fyrstenborg
    0

    Hi Palle

    Which version of Tea Commerce do you use?

    If you use Tea Commerce 3 and have used the "old" starterkit, google-ecommerce-tracking.cshtml need some changes according to the price object .. and in Tea Commerce 2 I also think GetCurrentOrder and GetCurrentFinalizedOrder has changed during the updates.

    Does your code look like this?

    @using umbraco.MacroEngines
    @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);
    
    <script type="text/javascript">
    
    _gaq.push(['_addTrans',
        '@finalizedOrder.OrderNumber', // transaction ID - required
        '@TC.GetStore(storeId).Name', // affiliation or store name
        '@finalizedOrder.TotalPrice.Value.WithVat.ToString("0.##", CultureInfo.InvariantCulture)', // total - required
        '@finalizedOrder.TotalPrice.Value.Vat.ToString("0.##", CultureInfo.InvariantCulture)', // tax
        '@finalizedOrder.ShipmentInformation.TotalPrice.Value.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.Value.WithVat.ToString("0.##", CultureInfo.InvariantCulture)', // price
        '@orderLine.Quantity' // quantity
    ]);</text>
        }
    _gaq.push(['_set', 'currencyCode', '@TC.GetCurrency(storeId, finalizedOrder.CurrencyId).IsoCode']);
    _gaq.push(['_trackTrans']);
    </script>
    }

    /Bjarne

  • Palle Hansen 143 posts 396 karma points
    May 04, 2015 @ 09:30
    Palle Hansen
    0

    Hi Bjarne.

    I'm using TC 2.3.0 and my code is not like yours. My code is this:

    @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.WithVatFormattedWithoutSymbol', // price

        '@orderLine.Quantity' // quantity

    ]);</text>

        }

    _gaq.push(['_set', 'currencyCode', '@TC.GetCurrency(storeId, finalizedOrder.CurrencyId).IsoCode']);

    _gaq.push(['_trackTrans']);

    </script>

    /Palle

  • Bjarne Fyrstenborg 1257 posts 3803 karma points MVP 6x c-trib
    May 04, 2015 @ 09:45
    Bjarne Fyrstenborg
    0

    Yes, in Tea Commerce 3 the price object was restructured, to prior Tea Commerce 3 e.g. this line:

    finalizedOrder.TotalPrice.Value.WithVat.ToString("0.##", CultureInfo.InvariantCulture)

    would look like this:

    finalizedOrder.TotalPrice.WithVat.ToString("0.##", CultureInfo.InvariantCulture)

    without the "Value" part.

    Furthermore I think previously it was a problem to use WithVatFormattedWithoutSymbol here because you send a price like 200,00 in Danish, but Google Analytics expect a dot a decimal separator - so 200.00 and instead it should also send the currency code.

    When you reach the confirmation page, has it create a new order and does it display the order info e.g. the OrderNumber?

    /Bjarne

  • Palle Hansen 143 posts 396 karma points
    May 04, 2015 @ 12:36
    Palle Hansen
    0

    The order is created when I reach the confirmation page, and the OrderNumber is displayed.
    I've tried to put in your code, but that give med this error: 

    Error occured

    c:\www\godebørnebøger.dk\www\public\macroScripts\cart\635663397142392109_google-ecommerce-tracking.cshtml(18): error CS1061: 'decimal' does not contain a definition for 'WithVat' and no extension method 'WithVat' accepting a first argument of type 'decimal' could be found (are you missing a using directive or an assembly reference?)

     

    /Palle
     

  • Anders Burla Johansen 2560 posts 8256 karma points
    May 04, 2015 @ 15:39
    Anders Burla Johansen
    0

    Hi Palle

    The code that Bjarne has posted is for Tea Commerce 3 - and you are using Tea Commerce 2, so don't use the exact code. If the order is finalized then the problem is properly with how you use the data. If you use Visual Studio you should have code completion for the Order object. Try and remove almost everything from the google tracking until it works. Then find which line that exactly fails and then post the code for that line.

    Kind regards
    Anders

Please Sign in or register to post replies

Write your reply to:

Draft