Page 2 of 2

Re: Google Remarketing

Posted: Thu Aug 20, 2015 10:32 am
by rmaweb
No I haven't gotten to the point where I could go to Google and test the friendliness of it. The errors Im getting are catalog errors when pulling the data to put in the datalayer.

Re: Google Remarketing

Posted: Tue Feb 16, 2016 8:36 am
by kwikstand
Mazhar,

On that ConLib, doesn't it need a GoogleRemarketing.ascx.cs file and something like <%@ Register src="~/ConLib/GoogleRemarketing.ascx" tagname="GoogleRemarketing" tagprefix="uc" %> in the head of the page?

Re: Google Remarketing

Posted: Tue Oct 25, 2016 3:39 am
by jill224
I was wondering if anyone has had any luck since these posts in successfully implementing the Google Dynamic Remarketing tag on all the necessary pages? After looking through a few posts, including this one, I was able to successfully get the code to work and pass on the product ids to Google through inserting the following tag as a control inserted on the individual Product pages:

Code: Select all

<script runat="server">
    int ProductId { get; set;}
    decimal Price { get; set;}
    protected void Page_PreRender(object sender, EventArgs e)
    {
        CommerceBuilder.Products.Product product = CommerceBuilder.Products.ProductDataSource.Load(AbleCommerce.Code.PageHelper.GetProductId());
        if (product != null )
        {
            ProductId = product.Id;
            Price = product.Price;
        }
    }
</script>

<script type="text/javascript">
var google_tag_params = {
ecomm_prodid: <%=ProductId%>,
ecomm_pagetype: 'product',
ecomm_totalvalue: <%=Price%>,
};
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = xxxxxxxx;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/xxxxxxx/?guid=ON&script=0"/>
</div>
</noscript>
I have been using the Google Tag Assistant tool and did speak to Google and they confirmed this was working correctly and passing on the info they needed specifically for the product pages.

The problem I am running into is that Google is telling me they also need similar code inserted on the cart, checkout and purchase/receipt page to pick up the product ids and value on these pages as well as the "page type" (cart, purchase, etc). I can not seem to get this to function properly on these pages because it will not pick up the products or value correctly when multiple products are listed on the same page (such as in the cart setting).

If any one has been able to do this successfully and can pass on any help or point me in the right direction I would really appreciate it!

Re: Google Remarketing

Posted: Tue Oct 25, 2016 5:10 am
by nadeem
Have you looked into this thread viewtopic.php?f=65&t=18901&p=83194#p83200 by any chance? This may help you moving forward. Thanks.

Re: Google Remarketing

Posted: Tue Oct 25, 2016 5:38 am
by jill224
Hi Nadeem,

Yes - I did actually refer to that thread and a few others related to Conversion Tracking, Remarketing, etc. I have tried a bunch of things and variations of the code but have still been unable to get anything to work other than the individual product pages.

It seemed like I was having the same issue as the other poster as far as problems with the other "page types." I did see the code you posted near the bottom of the thread, but I am by no means an expert and I was not sure how to modify this to function properly and pick up the multiple product ids and order total for cart and receipt pages.

Re: Google Remarketing

Posted: Wed Oct 26, 2016 2:34 am
by nadeem
I have updated your code so that it should work on your product, cart and receipt page. Here is the updated code:

Code: Select all

<script runat="server">
    string ProductId { get; set; }
    decimal Price { get; set;}
    string PageType { get; set; }
    decimal total = 0;
    List<int> ids = null;
    protected void Page_PreRender(object sender, EventArgs e)
    {
        ids = new List<int>();
        CommerceBuilder.Products.Product product = CommerceBuilder.Products.ProductDataSource.Load(AbleCommerce.Code.PageHelper.GetProductId());
        if (product != null )
        {
            ProductId = product.Id.ToString();
            Price = product.Price;
            PageType = "product";
        }

        CommerceBuilder.Orders.Order order = OrderDataSource.Load(AbleCommerce.Code.PageHelper.GetOrderId());
        if (order != null)
        {
            foreach(OrderItem oi in order.Items)
            {
                if (oi != null && oi.ProductId > 0)
                    ids.Add(oi.ProductId);
            }

            ProductId = string.Join(",", ids.ToArray());
            Price = order.TotalCharges;
            PageType = "purchase";
        }

        if (Request.RawUrl.ToLowerInvariant().EndsWith("basket.aspx"))
        {
            Basket basket = AbleContext.Current.User.Basket;
            foreach (BasketItem item in basket.Items)
            {
                if (item != null && item.ProductId > 0)
                {
                    ids.Add(item.ProductId);
                    total += item.ExtendedPrice;
                }
            }

            ProductId = string.Join(",", ids.ToArray());
            Price = total;
            PageType = "cart";
        }
    }
</script>

<script type="text/javascript">
var google_tag_params = {
ecomm_prodid: <%=ProductId%>,
ecomm_pagetype: <%=PageType%>,
ecomm_totalvalue: <%=Price%>,
};
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = xxxxxxxx;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/xxxxxxx/?guid=ON&script=0"/>
</div>
</noscript>
You can put this code in a new control and place it in storefooter.ascx just below google analytics control.

Re: Google Remarketing

Posted: Wed Oct 26, 2016 5:50 am
by jill224
Hi Nadeem,

I did insert this code in a control in the store footer. There still appears to be a problem on the pages such as the cart with multiple products listed per page.

Google Tag Assistant is showing an error reading that "Tag Paramater object could not be parsed."

This is an example of the Conversion Tag parameters as they are showing in Tag Assistant:

ecomm_prodid: 3227, 4599:, 376:, ecomm_pagetype: cart, ecomm_totalvalue: 76.9700, :

Do you have any idea what might be causing this issue or what changes can be made to resolve it? I really do appreciate you taking the time to help me with this!

Re: Google Remarketing

Posted: Thu Oct 27, 2016 12:49 am
by nadeem
Try replacing the below code

Code: Select all

ecomm_prodid: <%=ProductId%>,
ecomm_pagetype: <%=PageType%>,
with

Code: Select all

ecomm_prodid: [<%=ProductId%>],
ecomm_pagetype: '<%=PageType%>',

Re: Google Remarketing

Posted: Fri Oct 28, 2016 6:23 am
by jill224
Nadeem, thank you so much for all of your help with this. I replaced that code with the brackets and it is now working correctly to get the product ids on pages where multiple items are present. I did speak with Google yesterday after doing this and they confirmed that the code is working properly for all product, cart and purchase pages.

They are now informing me that the next issue is that they need additional pagetype params to be present on Home page ("home"), Category pages ("category"), search results pages ("searchresults"), and all remaining pages that do no fit into these types to be labeled as "other".

I was able to easily get the home page tagged by adding code similar to what was used for the "Basket.aspx" page. But I am not sure what type of logic to use to get the category, search results, and all "other" page types tagged properly. Do you or anyone else have any suggestions as to what can be done to get these additional pagetype params added? I am hoping this is the final issue that needs to be resolved before we can actually move forward with getting our dynamic remarketing campaign up and running. Thank you again for everything!

Re: Google Remarketing

Posted: Mon Oct 31, 2016 3:43 am
by nadeem
Here is the code to get page types for category and search results (both simple and advanced search) pages. If the page type is none of the specified types, it should go to 'Other'.

Code: Select all

var categoryId = AbleCommerce.Code.PageHelper.GetCategoryId();
        var category = CategoryDataSource.Load(categoryId);
        if (category != null)
        {
            string categoryUrl = category.NavigateUrl.Replace("~/", "");
            if (Request.RawUrl.EndsWith(categoryUrl))
            {
                PageType = "category";
            }
        }

        if (Request.RawUrl.ToLowerInvariant().Contains("search.aspx")
            || Request.RawUrl.ToLowerInvariant().Contains("advancedsearch.aspx"))
        {
            PageType = "searchresults";
        }

        if (PageType == null)
            PageType = "Other";

Re: Google Remarketing

Posted: Tue Nov 01, 2016 11:26 am
by jill224
Nadeem - you have been extremely helpful with this and I truly do appreciate you taking the time to respond to me with these answers! I spoke with Google again yesterday and they confirmed that the code/tag is now working properly and passing on all the necessary data they need for all pages on the website to go ahead with Dynamic Remarketing.

I know some other users were having problems with this issue in the past so I am going to post the full code that I used below in case it will help anyone else. This code was used to create a "Google_Remarketing" Control which was then inserted on the StoreFooter.ascx file that appears on all pages on the site:

Code: Select all


<script runat="server">
    string ProductId { get; set; }
    decimal Price { get; set;}
    string PageType { get; set; }
    decimal total = 0;
    List<int> ids = null;
    protected void Page_PreRender(object sender, EventArgs e)
    {
        ids = new List<int>();
        CommerceBuilder.Products.Product product = CommerceBuilder.Products.ProductDataSource.Load(AbleCommerce.Code.PageHelper.GetProductId());
        if (product != null )
        {
            ProductId = product.Id.ToString();
            Price = product.Price;
            PageType = "product";
        }

        CommerceBuilder.Orders.Order order = OrderDataSource.Load(AbleCommerce.Code.PageHelper.GetOrderId());
        if (order != null)
        {
            foreach(OrderItem oi in order.Items)
            {
                if (oi != null && oi.ProductId > 0)
                    ids.Add(oi.ProductId);
            }

            ProductId = string.Join(",", ids.ToArray());
            Price = order.TotalCharges;
            PageType = "purchase";
        }

        if (Request.RawUrl.ToLowerInvariant().EndsWith("basket.aspx"))
        {
            Basket basket = AbleContext.Current.User.Basket;
            foreach (BasketItem item in basket.Items)
            {
                if (item != null && item.ProductId > 0)
                {
                    ids.Add(item.ProductId);
                    total += item.ExtendedPrice;
                }
            }

            ProductId = string.Join(",", ids.ToArray());
            Price = total;
            PageType = "cart";
        }
		
		
		 if (Request.RawUrl.ToLowerInvariant().EndsWith("default.aspx"))
        {
           
            PageType = "home";
        }
		
		
		var categoryId = AbleCommerce.Code.PageHelper.GetCategoryId();
        var category = CategoryDataSource.Load(categoryId);
        if (category != null)
        {
            string categoryUrl = category.NavigateUrl.Replace("~/", "");
            if (Request.RawUrl.EndsWith(categoryUrl))
            {
                PageType = "category";
            }
        }

        if (Request.RawUrl.ToLowerInvariant().Contains("search.aspx")
            || Request.RawUrl.ToLowerInvariant().Contains("advancedsearch.aspx"))
        {
            PageType = "searchresults";
        }

        if (PageType == null)
            PageType = "Other";
		
		
    }
</script>

<script type="text/javascript">
var google_tag_params = {
ecomm_prodid: [<%=ProductId%>],
ecomm_pagetype: '<%=PageType%>',
ecomm_totalvalue: <%=Price%>,
};
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = xxxxxxxxx;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/xxxxxxxxxx/?guid=ON&script=0"/>
</div>
</noscript>


Re: Google Remarketing

Posted: Tue Nov 01, 2016 11:09 pm
by nadeem
Glad to know this is all working good for you. Thank you for putting together the whole code and sharing with others to get benefit.

Re: Google Remarketing

Posted: Sun Sep 03, 2017 3:53 am
by kwikstand
This works pretty good, except for one thing. The Product Id is wrong, at least for me. It is returning the "item_group_id" rather than the "id" and doesn't match up with the feed.

I think it only does this for products with variants. I am using the Google Feed and for products with Publish Feed as Variants checked, I get the "item_group_id" instead of the "id"