Copied to clipboard

Flag this post as spam?

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


  • Henrik Vincent 122 posts 616 karma points
    Feb 23, 2018 @ 08:37
    Henrik Vincent
    0

    Google Analytics e-commerce tracking in Merchello

    Hi guys

    I'm helping a client getting Google Analytics and AdWords e-commerce tracking running on his Merchello setup.

    Using Google Tag Manager.

    But I'm having problems.

    When placing a test order I get the following error

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
    
    Compiler Error Message: CS1012: Too many characters in character literal
    
    Source Error:
    
    
    Line 137:      @foreach (var item in Model.Items.Where(x => x.LineItemType == LineItemType.Product))
    Line 138:        {
    Line 139:        'products': [{              // List of productFieldObjects.
    Line 140:          'name': '@item.Name',     // Name or ID is required.
    Line 141:          'id': '@item.Sku',
    

    I'm suspecting, that the curly boys { } in the within the foreach loop is causing the error, but I'm not experienced enough to just fix it.

    Hope any of you guys can help, because I havent been able to find any similar posts about this.

    Best

    Henrik

  • Kerri Mallinson 113 posts 497 karma points
    Apr 18, 2018 @ 10:50
    Kerri Mallinson
    1

    Hi Henrik,

    Did you manage to resolve this? I only just noticed your post whilst investigating some issues i'm also having with integrating GA ecommerce with Merchello.

    pushing product data on pageview can be done like this, if it helps?

    <script>
    dataLayer.push({
        'ecommerce': {
            'impressions': [
                {
                    @foreach(var product in Model.Products)
                    {
                        var name = product.Name;
                        var id = product.Sku;
                        var price = product.Price;
                        var brand = "test";
                        var category = "test";
                        var list = "test";
        <text>'name': '@name', 'id': '@id', 'price': '@price', 'brand': '@brand', 'category': '@category' ,'list': '@list'</text>
    }
                }],
        }
    });</script>
    

    Kerri

  • Henrik Vincent 122 posts 616 karma points
    Apr 25, 2018 @ 13:08
    Henrik Vincent
    0

    Hi Kerri

    Thanks a lot for your reply.

    I'm gonna give it a go next week.

    Best
    Henrik

  • Kerri Mallinson 113 posts 497 karma points
    Apr 25, 2018 @ 13:21
    Kerri Mallinson
    0

    Hi Henrik,

    In that case, can I offer an amendment to the previous code (after more testing it wasn't quite right)

    The below is how we can get a product impression pushed to the data layer for each of the products on the product list page:

    <script>
    dataLayer.push({
        'ecommerce': {
                'impressions': [
                    @{
                        var items = Model.Products;
                        var count = 0;
                    }
                      @foreach (var item in items)
                      {
                          ++count;
    
                          var name = item.Name;
                          var price = item.Price;
                          var brand = "XX Brand";
                          var id = item.Sku;
                          var list = Model.Name;
                          var category = "XX Category";
    
                  <text>{ 'name': '@name', 'id': '@id', 'price': '@price', 'brand': '@brand', 'category': '@category', 'list': '@list' }@(count != items.Count() ? ",":"" )</text>
                    }]
        }
    });</script>
    

    Hope it goes well! Kerri

Please Sign in or register to post replies

Write your reply to:

Draft