Category Archives: Google Analytics

Two Shopify Theme Edits to Improve Your Tracking

So, you’ve gone and gotten yourself a Shopify store. Congratulations! They’re an excellent platform that helps people build successful online stores. (And I’m not just saying that because I wrote for them before!)

But there’s two things it doesn’t do out of the box:

  1. Give you a unique URL to track new account creations.
  2. Give you a way to track outbound clicks.

This is amazingly easy to fix.

Track New Account Creations

Go to Themes > Edit HTML/CSS > customers/register.liquid. Edit HTML/CSS is under the … menu at the top.

2016-09-18_19-09-28

You need to add one line to your customer form.

      <input type="hidden" name="return_to" value="account/?acct=new" />

2016-09-18_19-05-09

You can change that ?acct=new to whatever you want. But by adding a parameter to the end of the URL people are directed to after signup, you can then create a Goal specifically for visitors to /account/?acct=new like this:

2016-09-18_19-14-29

Regular logins won’t go to that URL, just people filling out the account creation form.

Hat tip to Shopify customer forums user Caroline Schnapp for this solution, originally found in this thread.

Tracking Outbound Links

Tracking outbound links can be a great way to see who’s getting to your social media from your storefront, or any other outside links you might have.

Sivakumar at EcommPPC has a script snippet that solves this. (Note: This is for Universal Analytics. If you’re still using the old version for some reason…. UPGRADE.)

<script>
$(document).ready(function(){
 var localserver = "mysite.com";
 $("a").not("a[href^='http://"+localserver+"']").not("a[href^='https://"+localserver+"']").click(function(){
 $(this).attr("target", "blank");
 ga('send', 'event', 'links', 'click', $(this).attr('href'));
 });
});
</script>

I’m reposting the script here to provide a version that doesn’t have curly/fancy quotes.

Change “mysite.com” in the above script to the primary domain of your store. (Not the full URL with http, just the domain name.)

Add the script just after the opening <body> tag. Now links to other websites posted anywhere on your Shopify store will be tracked as Events in Google Analytics. This script will tag them all as Category “links” and Action “click”. The label will be the full URL the visitor clicked.  I might recommend changing “links” to “Outbound Links” or just Outbound, to make sure your event category is as clear as possible.

I used this recently to track clicks to a booking page on Calendly.

2016-09-18_19-25-01

 

So that’s it! Two ways to quickly and vastly improve your tracking when using Shopify!

Get Bunk Referrer Semalt OUT of Your GA Stats

Ugh, semaltI help several small & local businesses get their web tools up and running, and few things are more disappointing than when garbage like “semalt” shows up in the results.

Semalt claims to be an SEO and Analytics tool, but word around the web suggests they are, at best, a cause of referral spam.

Referral spam, in general, is when a robot (think the Googlebot, a site crawler robot that helps index your site in Google’s search results) is sent to check out your website, but pretends to be a person by using falsified referrer header data.

bots difference

 

This is typically done via falsifying the Referrer and  User Agent parts of the header data.

The User Agent header tells the website and tools like Google Analytics what the visitor used to access the site.

Here’s a User Agent example from Chrome running on Windows 8:

Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36

Googlebot, your friendly neighborhood web crawler and search indexer, identifies itself with User Agents that look like this:

  • Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
  • Googlebot/2.1 (+http://www.googlebot.com/bot.html)
  • Googlebot/2.1 (+http://www.google.com/bot.html)

(Source : http://www.useragentstring.com/pages/Googlebot/)

You probably get a fair amount of referral spam without even realizing it! Google Analytics will only show/capture traffic data from visitors that can execute javascript, and use cookies (those tiny files that hold bits of data a server can use to recognize you later). If odd bots are probing your site, even ones with fake human credentials, but can’t execute javascript or use cookies.

The reason that Semalt appears in your Google Analytics? It pretends to be a human better than most bots.

Apologies to anyone with arachnophobia.
Totally legit. Source: http://imgur.com/gallery/UceXs6C

 

It’s up in your business, pretending to be a real visitor and possibly perpetuating further spam using your site. At minimum, it’s mucking up your data.

How to handle this?

You can deal with Semalt and bot traffic in one of three ways (or all three, honestly).

Option 1: Use GA’s autobot blocker

No it’s not going to prevent the Transformers from finally showing up to give you the birthday you’ve wanted since you were five.

Check your settings!

Go to the View settings for your website’s GA account. Check the Bot Filtering box. Save settings.

This option uses the IAB/ABC International Spiders & Bots list to help clean and press your traffic data against known robots.

If you decide to use this feature, you should make sure to create a “Raw Data” View without this – or any other – filter in place. This will give you a point of comparison in the event your data looks really unusual after implementing a major filter change.

Because it’s faking coming from a real browser and can execute javascript, this probably won’t block Semalt. But it is a good way to prevent known bots from blowing up your stats.

Option 2: Create a filter

Creating Filters in Google Analytics sounds a little scary, but it’s not.

Step 1: Go to the Filters section in your Admin area Under View and select +New FilterCreate a new filter

Step 2: Name your Filter. Something like “Semalt” will do just fine.
2015-02-03_14-43-32
Step 3: Click on Custom
Step 4: Select Referral from the Filter Field list
2015-02-03_14-35-33
Step 5: Type semalt\.com into the Filter Pattern box. (The \ is important because this field uses Regular Expressions!)
2015-02-03_14-39-53Step 6: SAVE!

Note: If you’re using Filters you absolutely should be setting up a Raw Data profile! Making mistakes with Filters can throw your data off pretty badly, and having a Raw Data (aka no Filter) profile gives you a way to sanity check your data, and provides a backup in case of data lost to Filter mishaps.

This filter will not change your historical data, sorry. You’re stuck with your prior Semalt traffic in your reports. But from the time you make the Filter live onwards, Semalt as a Source/Referrer will no longer appear in your reports. This only cleans up your reports, it doesn’t keep them from crawling your site.

Option 3: Knock knock! who’s there? NOT YOU! (AKA the htaccess option)

So, you’ll need to actually be able to edit your site’s .htaccess file, and it helps to have a basic idea of how to use it (or at least not break it).

But the good news is, blocking them is as simple as adding the following to the bottom of your .htaccess:

SetEnvIfNoCase Referer semalt.com spammer=yes

Order allow,deny
Allow from all
Deny from env=spammer

(Source: WordPress Codex example)

If that’s not working  – and you can check that Raw Data profile you set up to figure out if it is or not  😉 – or you’re getting a bunch of new garbage, then it’s time to hit more .htaccess resources. Your web host may be able to help you out, too.

So that’s it!

For another Google Analytics Filter set to get rid of other bots using the “Mozilla Compatible Agent” browser User Agent, check out this Filter from LunaMetrics.

 

Tracking Non-Page Activity With Google Analytics (updated 3x)

First, let’s define what “non-page activity” means: non-page activity is any action that happens on your website that isn’t a page load or page view. That includes: button clicks that don’t lead to a new page, media player uses, and file downloads.

Google Analytics, and any other javascript-based site tracking tool, can’t track the activity of any area of your website where the tracking script doesn’t appear. That means that the PDF link you put up won’t get tracked in your regular reports without some extra effort.

The easiest and most detailed way to track these sorts of things is to implement something called Event tracking.

First: Are you using Universal Analytics, or original flavor Google Analytics?

If you aren’t sure, do this:

  • Log into Google Analytics
  • Go to Admin (upper navigation, furthest option to the right)
  • Expand the “Tracking Info” section under Property (center column)
  • Click Tracking Code

Click to make bigger

If the tracking snippet looks like this, It’s Universal:

universal tracking example

If the tracking snippet looks like this, it’s classic GA:

old tracking code
Pulled from the developer docs area.

 

If you’re running Classic Google Analytics, I’d recommend upgrading before proceeding to implement Event tracking. It’s relatively painless, and they are working on making Universal the standard for all GA users in the not-too-distant future.

Second question: Are you running WordPress, or using a different way to manage your website content?

If you are running WordPress, I highly recommend picking up the GA plugin created by Audrius Dobilinskas. They make tracking all types of downloads and outbound clicks as simple as a checkbox. Let’s run through this, as it’s the quickest and easiest way I know of to get file download and outbound link tracking into place.

Installing and Using a GA Plugin to Track Downloads as Events

Search “google universal analytics” in the plugin installer of WordPress and this will be the first option. Select Install, and after installing, activate the plugin.

You’ll have a new menu at the bottom of your WordPress left hand menu options called Google Universal Analytics, with a gear icon.

Click this to go to the default page, which is the settings for Universal Analytics. This plugin also provides options for Classic Analytics, and custom code.

UA settings

You’ll need to set the status to “on” and plug in your Tracking ID into the box. You can get your Tracking ID by following the same steps you used earlier to see which version of GA you are running. You can also get your ID from the Property Settings page, seen here:

property settings

To track your file downloads and outbound clicks, check the box next to “Track Events”.  Make sure to save your settings!

That’s it. You’re done. You’re now tracking your site visitors, outbound clicks, and downloads.

The default behavior is to track outbound clicks and downloads as Events.

Let’s Talk About Event Tracking For a Sec

Pros of using Events:

  • Neat, separate reporting
  • 4 distinct reports: overview, top events, pages, events flow

Cons of using Events:

  • Very few!

Events reporting is pretty robust, and it does allow you to see what pages the actions occurred on, which will allow you to backtrack as needed.

You also get 4 possible layers of labeling for events: Category, Action, Label, and Value.

Category is the grouping, such as “File Downloads” or “Videos”.
Action is a sub category to track the literal action that takes place in the event, such as “play” or “share” or “download”.
Label is a third tier of labeling you can use to get specific about the action in that category where you can put file names or other types of classifications, such as “PDF newsletter 34″‘ or “My Movie Unabridged”.
And finally Value, which is any positive number you can use to assign numeric value to your event.

Ok but I don’t have WordPress, so what do I do?

don't cry! We got this!

Ok. So you’ll need to have the ability to edit pages on your website and/or the ability to write and implement basic jQuery.

It’s not as bad as it seems. The GA Developer Docs has the details of integration using jQuery, but allow me to paraphrase to save you a trip. (Frankly that’s one of the worst looking developer documents I’ve ever seen them put out. Clear as mud!)

If the idea of implementing jQuery sends you into a state of low grade shock, do not panic. You can make on page changes to your links to implement Event Tracking.

Andy Forsberg put up a piece on Penguin Initiatives that has some great examples of how to implement Event tracking with GA Universal by hand. It’s generally geared toward WordPress, but it can certainly apply to any site where you have the ability to edit pages and add files.

The part that applies to you, the not-really-a-coder reader, is this:

<div id="text-27">
 <h3>Subscribe</h3>
 <div>
 <a onclick="ga('send', 'event', 'RSS', 'Click', 'All Pages - Sidebar Widget - RSS - Text Link');" href="http://penguininitiatives.com/feed/">RSS</a>
 </div>
</div>

By adding an onclick event to your files and outbound links, you can track these things as Events. Easy-peasy, right?!

Now, a few things you need to know:

  1. The part that reads onclick=”ga(‘send’, ‘event’,  always has to be there, or it won’t work. This is the part that tells your browser “When a visitor clicks this, tell GA to send an event. Everything that follows after that are your semantic labels.
  2. Always make sure your Event ends with ‘);”  if that tiny bit of syntax is off, your Event won’t work. This is easy, but picky.
  3. The order of items after ‘event’, are: Category, Action, Label, and Value. Category and Action are required every time.
  4. Make sure each thing is wrapped in single quotes ‘like this’ and followed by a comma, ‘like this’, 
  5. Don’t use double quotes, single quotes, or commas in Category, Action, Label, or Value. Something like ‘joes chicken shack’, would break your event. Why? Because of the single quote (aka apostrophe) in “joe’s”.
  6. Keep it simple. Come up with Categories like “Files” and “Outbound” to use on all your file downloads and outbound links. Use Actions that are very clear, like “download” and “click”. Use Labels to get more detail, like “2014 TPS Report” or “Corporate Blog” to earmark specific files and links.

Test The Heck Out of Event Tracking

No matter what method you use to implement any type of new tracking, always, always, ALWAYS test it to make sure it’s working. Always. Seriously. ಠ_ಠ

The easiest way to test is to use the (constantly improving) Real-Time reports, which includes specific real time reporting for Events.

 

real time menu event

 

Click on your newly Event-tagged links, and watch for results. If you aren’t seeing anything, get friends and co-workers to click them also. If you still aren’t seeing anything after a minute or more (it’s really fast, it should be within a minute), then it’s time to debug!

After you get Event results in the Real Time reports, you need to follow up with the Event reports themselves. Check the Category, Action, Label, and Value for your tests. Does it meet your expectations? If not, it may be time to go check your implementation.

That’s it! Use it in good health!

 (ノ◕ヮ◕)ノ*:・゚✧

Edit: In a move straight out of the Irony Department, I installed and deployed Yoast’s GA plugin… without testing it. I discovered that my traffic from the last few days had no events! Whoa!

I did a few tests myself, and although the tracking code that plugin uses does capture traffic just fine, it was not sending Event data for outbound clicks. I suspect it has to do with the fact that my account has been upgraded to use Universal Analytics, while the code Yoast uses relies more on the older version.

So what you see above is a revised post, recommending a newer plugin that I have tested and does work. A little searching reveals that Yoast’s GA plugin isn’t supporting Universal Analytics, which is disappointing because their other plugins are actually quite good and are maintained regularly.

So not only is this a lesson in the follies of hastiness and blind trust of plugin creators, but it also hammers home: ALWAYS TEST.

Another Edit: Hey, so the plugin that I’ve switched to? Well, there was an update on 5/12/14 and now they provide eCommerce tracking support for WooCommerce, which is a highly popular online store application for WordPress. This plugin rules!

One More Edit: They had to remove the WooCommerce tracking feature due to compatibility issues. Still rules though. 🙂