Google Remarketing

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
rmaweb
Commander (CMDR)
Commander (CMDR)
Posts: 118
Joined: Fri Sep 10, 2010 9:41 am

Re: Google Remarketing

Post by rmaweb » Thu Aug 20, 2015 10:32 am

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.
Ryan A.
Scott's Bait and Tackle
http://store.scottsbt.com
Work In Progress
Able Gold R10
Bootstrap 3.3

kwikstand
Commodore (COMO)
Commodore (COMO)
Posts: 410
Joined: Mon Feb 19, 2007 8:12 pm
Contact:

Re: Google Remarketing

Post by kwikstand » Tue Feb 16, 2016 8:36 am

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?
Contractor's Solutions
www. contractors-solutions.net

jill224
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 23
Joined: Sat Aug 22, 2009 3:19 pm
Location: Northaeast Pennsylvania

Re: Google Remarketing

Post by jill224 » Tue Oct 25, 2016 3:39 am

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!

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 250
Joined: Tue Jul 31, 2012 7:23 pm

Re: Google Remarketing

Post by nadeem » Tue Oct 25, 2016 5:10 am

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.

jill224
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 23
Joined: Sat Aug 22, 2009 3:19 pm
Location: Northaeast Pennsylvania

Re: Google Remarketing

Post by jill224 » Tue Oct 25, 2016 5:38 am

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.

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 250
Joined: Tue Jul 31, 2012 7:23 pm

Re: Google Remarketing

Post by nadeem » Wed Oct 26, 2016 2:34 am

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.

jill224
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 23
Joined: Sat Aug 22, 2009 3:19 pm
Location: Northaeast Pennsylvania

Re: Google Remarketing

Post by jill224 » Wed Oct 26, 2016 5:50 am

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!

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 250
Joined: Tue Jul 31, 2012 7:23 pm

Re: Google Remarketing

Post by nadeem » Thu Oct 27, 2016 12:49 am

Try replacing the below code

Code: Select all

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

Code: Select all

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

jill224
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 23
Joined: Sat Aug 22, 2009 3:19 pm
Location: Northaeast Pennsylvania

Re: Google Remarketing

Post by jill224 » Fri Oct 28, 2016 6:23 am

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!

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 250
Joined: Tue Jul 31, 2012 7:23 pm

Re: Google Remarketing

Post by nadeem » Mon Oct 31, 2016 3:43 am

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";

jill224
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 23
Joined: Sat Aug 22, 2009 3:19 pm
Location: Northaeast Pennsylvania

Re: Google Remarketing

Post by jill224 » Tue Nov 01, 2016 11:26 am

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>


nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 250
Joined: Tue Jul 31, 2012 7:23 pm

Re: Google Remarketing

Post by nadeem » Tue Nov 01, 2016 11:09 pm

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.

kwikstand
Commodore (COMO)
Commodore (COMO)
Posts: 410
Joined: Mon Feb 19, 2007 8:12 pm
Contact:

Re: Google Remarketing

Post by kwikstand » Sun Sep 03, 2017 3:53 am

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"
Contractor's Solutions
www. contractors-solutions.net

Post Reply