How to Report WooCommerce Checkout Errors as Events in Google Analytics

For a while now, I have wanted to have visibility into what really happens on the WooCommerce Checkout page. More specifically, the goal is to determine why almost 50% of those visitors leave the site from the Checkout page?

Survey pop-ups could be one way of determining why they are leaving the site. However, personally, I consider those intrusive. Why not have a behind-the-scenes way of reporting the exact error(s) the user might be encountering?

At first, I envisioned that I could insert some JS code (specifically the GA Send Event JS code) within the relevant WooCommerce filter. In this case, it was going to be the “woocommerce_add_error” filter. However, that was not going to work, as I found that out after a bit of experimentation. Somehow, the JS code was being appended to the “checkout.min.js” file instead of being added inline. Later, I discovered that you can not add JS code in Filter Hooks. See this Facebook post in the Advanced WordPress group for that discussion.

The Solution

As I looked for how to solve this issue, another alternative method came to mind. What if I could trigger on the addition of the “<ul class=”woocommerce-error”>….</ul>” element to the DOM?

This way, the solution would be generic and can be extended for other notice types (warning, notice, message etc) as well. It could easily be used outside of the WooCommerce context as well. Ofcourse, you will have to change the correct class/id of the element being targeted.

Code Changes

Explanation:

The code changes are split into 2 parts:

  1. Load the new JS file from within the functions.php of your child theme.
  2. ga-send-error-event.js should be located in the “js” folder of your child theme. If the “js” folder” does not exist, you will have to create it.

Testing

Once you make these changes, you can test it yourself in Google Analytics. But first, you will have to conduct your testing in an Incognito window (Google Chrome).

  1. Visit your Checkout page (preferably in an uncached and incognito browser session)
  2. Open your Developer Toolbar from the Browser (Chrome Dev Tools or FireBug)
  3. Leave all fields empty.
  4. Select a Payment Method and click on Continue
  5. You should see the messages printed above the Checkout Form
  6. Log into your GA interface
  7. Navigate to Real-Time->Events->Events (last 30 minutes)
  8. You should see new events generated under the “WooCommerce Error” category.

See screenshots below

New Category of events called WooCommerce Error
New Category of events called WooCommerce Error

In my case I had left the Billing First Name and Billing Last Name empty. Additionally, I had also left the “Terms & Conditions” checkbox unchecked. The Event Label got truncated, but if you hover over it, the full label is :

“Billing First Name is a required field.,Billing Last Name is a required field.,You must accept our Terms &amp; Conditions.”
Event showing Full error message
Event showing Full error message

So this is how I solved the issue of reporting error messages on WooCommerce checkout page. I am not sure how helpful this will be (I am hoping it will lead to better insight into the actions of the user on the Checkout page). Hopefully, it will reveal weaknesses in the UX.

What do you think? Is this something useful for you? Go ahead and use the code. Let me know if it works well for you. You can also easily extend this code to any part of the site (it does not have to be WooCommerce related).

AdWords Location Options Target and Exclude

You may have setup several Ad campaigns in Adwords. One of the setup options is related to Location. I did not give this one setting much importance. Instead, I would just enter the Country to target and forget about the rest. My assumption was that since I was “Targeting” visitors from just the one country, my ad would NOT be shown to anyone outside the targeted country.

Adwords Location Options
Ignore this at your peril. To target tightly, click on “People in my targeted location”

For example, I have Ad Campaigns targeting users exclusively in the United States. Or so I thought! My assumption was wrong, but I found out the hard way.

Accidental Discovery via Google Analytics

I was researching my site bounce rate when I stumbled upon the fact that my Adwords Ad was being displayed to users outside my “Target” country. This was totally unexpected because I did not intend to do that. I was trying to reach a specific country, but instead it turned out that users in other countries were being shown my Ad. Because this Ad was not relevant to them, my bounce rate associated with such visits was higher than 70%!

Through my newly learnt skills at segmenting data, I was able to narrow down specifically 3 countries whose visitors were showing an extremely high bounce rate. Note that these 3 countries were NOT my targeted countries.

Once I uncovered these wasted PPC clicks, I was determined to find out why AdWords was showing my ad. My first impulse was “ha, I found a bug in AdWords!”. Ofcourse, on deeper reflection, that was untrue. A bug like that could be of huge proportion and would have been caught much earlier.

Needless to say, I went digging through my Ad Campaign Settings. Specifically, I was seeking the answer within the Location Options settings.

Location Options (advanced) explained:

As it turns out, I had not read the instructions clearly. Part of the reason I overlooked this setting was because of the “recommended” default. The “Recommended” default option allows the ad to be shown to anyone in my targeted location, but also to anyone who “shows interest” in your targeted location. To make this clear, say you are selling “medicinal soap” through your Ads. Your “Target” country is United States. All is good so far, but what happens when a user searches for “medicinal soap in usa”? You guessed it right, the Ad is displayed.

What does this mean for me? In my case, I want a very tight control over what target country my ad is displayed in. Hence the “Recommended” defaults was not apt for my situation. I believe my choice would be “People in my targeted location“.

This setting would make sure that the Ad is never displayed outside of the Targeted country.

Also, keep in mind that the same settings apply for “Excluded” countries as well. The logic is the same, just conversely.

Conclusion

As I stated earlier, I was not looking at AdWords settings initially. My goal was to figure out why the bounce rate was so high for my site. This may be a small factor, but I am excited to see if the bounce rate will be lower, atleast for visits from the Adwords CPC medium.

 

[WooCommerce] Checkout Progress Bar

As you read articles/posts on ecommerce optimization, specifically checkout optimization, a popular theme emerges: The Checkout Progress Bar. The idea is to provide your visitors some kind of visual feedback that they are making progress. It tells them how far along they are before the purchase is complete. Conversely, it tells them how much longer before they can own the product/service they are vying for.

With this in mind, I googled for a free plugin that would accomplish just that. My search ended fruitless (almost). I did hit this gem of a plugin called Progress Bar. This is a simple plugin that can be used anywhere on a WordPress site.

Steps

In this article, my aim is to create your own customized checkout progress bar without the use of any paid plugins. You will need

  • Download the Progress Bar plugin from the WordPress plugin repository
  • Make some code changes (PHP and JS included). Download from github.

The code changes are shown below. The first change is in your theme/child theme’s functions.php file. Two things are happening here:

  1. Hooking into the “woocommerce_checkout_before_customer_details” action hook to display the Progress Bar. We use the shortcode for the Progress Bar because it allows to send in parameters for styling and appearance.
  2. Loading the JavaScript file that will manipulate the Progress Bar based on how much of the Checkout Form has been validated.

The second file is the JS script that checks in real-time which mandatory fields have been validated. Then it calculates the progress (in pixels) by simply dividing the “number of fields validated” by the “number of fields that require validation”. It also accounts for the “Shipping Address Same as Billing Address” checkbox.


The end result is you get a progress bar for your WooCommerce Checkout Page.

WooCommerce Checkout  Progress Bar in Action
WooCommerce Checkout Progress Bar in Action

Notes on Customization

The CSS for the progress bar can be easily customized. Follow the instructions on this link. Also, note that the plugin has quite a few options that can be used for customizing the look and feel of the Progress Bar.

[SOLVED] How to trigger emails of Failed Orders in WooCommerce

Update on February 3rd, 2016:

As of version 2.5 of WooCommerce, this functionality is now built into the WC Core. This plugin is not needed. See the WC 2.5 Changelog for more details.

 

Following the lead from this blog post by SkyVerge, I set upon to create email notifications when an order fails. Essentially, any time the credit card fails or the order processing is not successful, WooCommerce should notify the store owner that the order has failed.

Currently, WooCommerce is silent about Failed Orders. Note that there is a built in setting in WooCommerce for notifications about Canceled Orders, but not Failed Orders.

My first attempt at trying to modify this plugin by Justin Stern, failed. I tried to adapt the plugin for “Failed” instead of “Cancelled”. However, just replacing the instances of “Canceled” with “Failed” did not accomplish my objective.

After a lot of experimenting, I gave up and sought the help from the WooCommerce community. One of the most helpful WooNinjas, Caleb Burks, lent me a hand for this one. I take no credit for this. All I can say is that guy knows his coding very well.

In the future, I will try to explain the code. For now, here is the link to the completed plugin that sends out emails immediately after an order transitions into Failed status. To test this, simply change the status of an order to “Failed”. Emails should be fired off to the store owner.

Good luck to you. Let me know if it works or if you experience problems. This does work on my setup: WordPress 4.3.1, WooCommerce 2.4.6.

 

[Fixed] Infinite Redirect after switching WooCommerce site to SSL

According to Google’s Webmaster Blog, they are going to consider HTTPS as a ranking signal.  With this announcement, it becomes important that site owners switch their entire site to HTTPS.

If you already have SSL on all your pages, you do not need to do anything. However, I had a case where only the Checkout and Account pages were SSL protected. The rest of the site was not SSL protected.

I embarked on the journey to convert an e commerce site to HTTPS on all pages. Doing the conversion itself was easy. I used this guide to transfer the site to HTTPS.

However, the problem was I was receiving the dreaded infinite redirect message from Chrome. Initially, I thought it was a local browser cache issue. That was not the case. Digging deeper using Google Chrome’s FireBug tool, I determined that the http://www.example.com was redirecting to https://www.example.com. In turn the latter would redirect to the former. This 2-way ping pong redirect would continue for about 3 or 4 times before the browser gives up and announces failure.

I found the issue was a non-trivial (in hindsight) setting under WooCommerce. Go to WooCommerce->Settings->Checkout->Force HTTP when leaving the checkout

Make sure that setting option “Force HTTP when leaving the checkout” is Unchecked.

When this option is checked, it will redirect all non-checkout pages to http. There lies the problem. The 301 site-wide redirect for http:// to https:// was conflicting with this WooCommerce setting. Each was reversing each other out, hence the infinite redirect.

I had posted in multiple online groups but never received a proper response, so I hope this helps someone.