Duplicate Google analytics tracking code

duplicate google analytics code and duplicate google analytics tracking code and duplicate campaign parameters google analytics
ErrolFord Profile Pic
Published Date:03-08-2017
Your Website URL(Optional)
Hacking Google Analytics What fun would Google Analytics be without a few tricks of the trade? Even though the default Google Analytics setup makes it a great tool to help web-site owners everywhere obtain highly insightful information, there are quite a num- ber of helpful tips, tricks, and customizations that can make all the difference for you. We like to call these “hacks,” and in this chapter you’re going to find a whole lot of ‘em. We’ve made it so that you don’t have to be a computer science major or an MIT doctoral candidate in order to apply some of these hacks—or, at least, be able to tell a webmaster or IT techie how to do them. Hopefully, you have free rein to make code modic fi ations on your site, but please keep in mind that not every off-the-shelf or turnkey solution will allow you to edit source code and make customizations. Please work with your vendor to implement changes to the Google Analytics Tracking Code. We have small hacks, big hacks, simple hacks, and a few complex hacks within the following pages. Which ones will be useful for you? A Review of Subdomain/Cross-Domain Tracking Some of you may be coming here because we recommended that you should from Chapter 6 (“E-commerce Concepts and Methods”). As we mentioned there, you don’t necessarily need to have an e-commerce storefront for tracking your subdomain(s) or your multiple domain(s). Perhaps you have a blog on a 219 220 Part IIIn Advanced Implementation subdomain from your primary domain (blog.yoursite.com), or maybe you have a sister web site as a part of your corporate umbrella (www.secondsite.com) that you’d like to track within the same Google Analytics profile. Let’s again review how to properly track your subdomain or a second domain. Tracking Subdomains On all pages of your main site and any subdomain site that you wish to track in one prol fi e, use the following _setDomainName function in your Google Analytics Tracking Code as shown. Don’t forget to keep the same UA number throughout: var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._setDomainName(“.yoursite.com”); pageTracker._trackPageview(); Naturally, replace.yoursite.com with your own domain name. Keep the lead- ing period on the tracking code on both web sites to ensure cookie integrity. Tracking Multiple Domains Whenever multiple domains are involved you’ll need to use both _setDomainName and _setAllowLinker on the Google Analytics Tracking Code on both web sites: var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._setDomainName(“none”); pageTracker._setAllowLinker(true); pageTracker._trackPageview(); You’ll also need to either use the _link function on all links that take users to and from each web site, or use the _linkByPost function on all forms that take a user to and from each web site On hyperlinks (_link): a href=”http://www.otherwebsite.com/” onClick=”pageTracker._link(‘http:// www.otherwebsite.com/’);return false;” Click here to go to our other web site/a On forms (_linkByPost): form action=”http://www.otherwebsite.com/processing.php” name=”form” method=”post” onSubmit=”pageTracker._linkByPost(this)” Not using either _link or _linkByPost on both web sites will cause the second web site to drop its own set of cookies during a visitor’s session, causing visitor Chapter 14n Hacking Google Analytics 221 and referral information to be lost. This is the number-one cause of self-referrals in reports (seeing your own web site as a top referring source). n o t e In Chapter 8, we recommended that you use calls to _setAllowLinker and _setAllowHash to track between multiple domains, instead of using a call to _setDomainName as we just did in the previous example. Both ways will most likely work, unless you have links between both sites that both use “www” and that don’t use “www” (Example: links going to bothhttp:// www.site.com andhttp://site.com). If this is your situation, you’ll want to use calls to _setAllowLinker(true) and _setAllowHash(false), instead of using calls to _setDomainName(none) and _setAllowLinker(true). Tracking Multiple Subdomains and Multiple Domains Here’s something we didn’t cover in Chapter 6. Let’s say you have four proper- ties that you’d like to track in a single profile: 1. Your main site (www.yoursite.com) 2. Your blog (blog.yoursite.com) 3. Your second site (www.secondsite.com) 4. Your second site’s careers section (careers.secondsite.com) In a situation where multiple domains and subdomains are involved, you’ll need to use three functions on all pages on all sites: _setDomainName, _setAllowLinker, and _setAllowHash. Look closely at the next two coding examples of the proper way to use _setDomainName on each site. We’ll use our four-site example to demonstrate: On all pages ofyoursite.com (www.yoursite.com andblog.yoursite.com): var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._setDomainName(“.yoursite.com”); pageTracker._setAllowLinker(true); pageTracker._setAllowHash(false); pageTracker._trackPageview(); On all pages of secondsite.com (www.secondsite.com and careers .secondsite.com): var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._setDomainName(“.secondsite.com”); pageTracker._setAllowLinker(true); pageTracker._setAllowHash(false); pageTracker._trackPageview(); You’ll also need to use either _link or _linkByPost on any links to and from each site. However, _link or _linkByPost is not necessary on links between subdomains 222 Part IIIn Advanced Implementation of each domain. (For example, don’t use _link or _linkByPost on links fromwww .yoursite.com toblog.yoursite.com, or fromwww.secondsite.com tocareers .secondsite.com). Setting up Duplicate Profiles Duplicate profiles have many different uses. You can create up to 50 separate profiles in one Google Analytics account, and the options are limitless as to what data you can track in each one of them. You can track 50 different web sites, all with different UA numbers, if you’d like to. However, with some nice filtering work you can do things like track all your Google AdWords data in its own profile from the same web site. Or track all e-mail marketing campaign data in its own profile. How about organizing your subdomain/multiple domain trafc fi with a few duplicate profiles? Let’s say you completed installing the Google Analytics Tracking Code, using the exact same tracking code on three separate subdomains that you wish to track in one profile: 1. Your main site (www.yoursite.com) 2. Your blog (blog.yoursite.com) 3. Your storefront (store.yoursite.com) Here, what we would do is have four profiles for the same web site—one profile that collects all three sites’ data (sometimes referred to as a “roll-up” profile), and an individual profile for each subdomain site. The main or master profile that collects the data for all three sites does not need anything done to it. However, each one of the three individual profiles will need to have an include l fi ter created for it. Remember, an include filter excludes everything but what you insert in its filter pattern. Create a filter for each individual profile with the specic fi ations shown in Figure 14-1, and apply it to the corresponding profile. You’ll need to do this for each duplicate profile you create. Filters can be created within each individual profile’s settings, or by clicking on the Filter Manager link, found toward the bottom of the Account Overview screen where all your profiles are listed. n o t e As you can see in Figure 14-1’s Filter Pattern field, the name of the domain (the hostname) is written in Regular Expressions format. If you are not comfortable with Regular Expressions yet, please review Chapter 10 once more. Or simply copy our examples straight from the book—but be extremely careful when doing so, as one single mistake in a character (even an extra white space) can cause your filter to not function, or to do something com- pletely unexpected and harm your data. Chapter 14n Hacking Google Analytics 223 Figure 14-1: Include filter by hostname Now let’s say that you want to track all your Google AdWords data in a dupli- cate profile, so that you can have an entire suite of reports with nothing but your AdWords marketing data. In that situation you’ll need not one but two include filters, as well as ensuring that you have Applied Cost Data checked. After you’ve created your duplicate profile for an existing domain, create two include filters with the following specic fi ations, and apply them to your newly created profile: Filter 1 Filter Type: Custom➪ Include Filter Field: Campaign Source Filter Pattern: google Case Sensitive: No Filter 2 Filter Type: Custom➪ Include Filter Field: Campaign Medium Filter Pattern: cpc Case Sensitive: No If you plan ahead you can make other duplicate profiles using an include filter, such as to track all your e-mail Marketing efforts in one profile. If you plan on using the Google Analytics URL Builder that we talked about in the previous chapter, you’ll want to use a consistent naming convention for your medium dimension for all your URLs. This makes creating these duplicate profiles much easier. 224 Part IIIn Advanced Implementation Let’s say that you’ve used the word “email” for your medium dimension in all the URLs of your e-mail marketing efforts. Create the following include filter for your duplicate profile and you should be good to go: Filter Type: Custom➪ Include Filter Field: Campaign Medium Filter Pattern: email Case Sensitive: No Another example of a duplicate profile that you could create would be one where you would exclude all your trafc fi from China, Japan, and South Korea. In this example you want any trafc fi from those countries to not be included in your report data. One exclude filter on a newly created duplicate profile can handle this request, with the exact specic fi ations below: Filter Type: Custom➪ Exclude Filter Field: Visitor Country Filter Pattern: chinajapankorea Case Sensitive: No n o t e A great way to check if your filter will work is to type in your filter pattern as you would when creating your filter in the filter tool at the bottom of most reports in Google Analytics. If the pattern works there as you want it to, it will also work as a filter. Why Create Duplicate Profiles? One question that you may be asking yourself is “Why should I create any dupli- cate profiles? Wouldn’t it be easier to just use an advanced segment and possibly a custom report to get what I want?” There are a few important reasons why. Creating a duplicate profile creates a permanent record of that trafc fi , based upon the filters that you apply to it. Advanced segments can be created and applied to reports, but they are not permanent. Duplicate profiles aren’t subject to data sampling and can be assigned user access—advanced segments can be subject to data sampling and at this time can only be shared via a permalink. The most important reason creating duplicate profiles can help is that certain reports in Google Analytics do not support advanced segments. These are the Keyword Position report, the Absolute Unique Visitors report, the Benchmarking Chapter 14n Hacking Google Analytics 225 report, the Site Overlay report, and the Funnel Visualization report. Creating a profile for all of your Google AdWords trafc fi , for example, enables you to view funnel visualization and site overlay data for that specic fi group of visitors, which can be invaluable in helping you to gain deeper insights into specic fi sets of visitors. Filtering Out Internal Trafc fi Along with subdomain/cross-domain tracking, excluding internal or corporate trafc fi is one of the things web-site owners ask about most frequently. You can do this in a number of different ways, depending on your situation. Excluding a Single IP Address If you—or everyone in your ofc fi e—use a single IP address to access the Web, you will need to apply an exclude filter with the following specic fi ations: Filter Type: Exclude all traffic from an IP address IP Address: 192\.168\.254\.254 You can also use the “Exclude all traffic from an IP address” filter type if your organization owns every IP address between and (where only the last octet of the IP address is different). You would use the following syntax in this situation: Filter Type: Exclude all traffic from an IP address IP Address: 192\.168\.254\. This filter will still work in this filter type because it will match only one IP address at a time, be it192.168.254.34,, or so on. Excluding Two (or More) IP Addresses Your IT director comes to you with two completely separate IP addresses to exclude from your Google Analytics reports. Let’s say they are and You can use a Custom➪ Exclude filter type, as shown in Figure 14-2. Notice the pipe symbol () between IP addresses—you can keep adding more IP addresses if the need arises. Keep in mind that the total length of the Filter Pattern field must not exceed 255 characters. 226 Part IIIn Advanced Implementation Figure 14-2: Excluding two IP addresses Excluding a Range of IP Addresses Imagine that you are the administrator of the Google Analytics account for a large organization that has a large range of IP addresses for all the computers on its network. That range of IP addresses just happens to be every IP address between192.168.30.75 and192.168.50.102. If you are fantastic with Regular Expressions you will be able to write the filter in no time to exclude this range of IP addresses: Filter Type: Custom➪ Exclude Filter Field: Visitor IP Address Filter Pattern: 192\.168\.(30\.(7(5 -96-90-9)2(55-96-9 0-9)3(0-90-9)4(0-90-9)5(0-90-9)6(0-90-9)7(0-9 0-9)800)((31-940-9)\.(0-91-90-91(0-90-9)2(0-4 0-950-5)))50\.(0-91-90-91(00-2))) Yikes That’s a massive filter pattern, is it not? Even if you wrote the book on Regular Expressions, there’s a far simpler way to come up with that same filter pattern without much hassle at all. Simply use the IP address range tool shown in Figure 14-3, from the Google Analytics Help Articles. This tool can create complex Regular Expressions like the previous one, or simple ones if you type in only one IP address, so it can be helpful if creating filters is something you’re still getting used to. This very helpful tool can be found at the following address: http://www.google.com/support/analytics/bin/answer .py?hl=en&answer=55572 Chapter 14n Hacking Google Analytics 227 Figure 14-3: Creating a Regular Expression for a range of IP addresses Excluding Internal Trafc fi That Uses Dynamic IP Addresses If your organization uses dynamic IP addresses you won’t be able to use the Visitor IP Address filter field to exclude your company’s traffic (as your IP address is different with every visit). Most folks make the mistake of blocking the city (or cities) where their ofc fi es are located when dynamic IPs are involved, but of course that means that anyone else from those same locations will also not be reported. What you can do instead is follow these steps. You will need the support of your colleagues on this one. 1. Create a simple web page, give it a unique name, and upload it live to your web server. Don’t link this page from your navigation or integrate it with your site in any way—you don’t want anyone in the world to have access to this page. On this page install the Google Analytics Tracking Code as you normally would on any other page on your web site. However, you will be adding a call to _setVar exactly as shown. (We talk more about _setVar a little later on in this chapter.) script type=”text/javascript” var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : 228 Part IIIn Advanced Implementation “http://www.”); document.write(unescape(“%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”)); /script script type=”text/javascript” try var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._trackPageview(); pageTracker._setVar(“employees”); catch(err) /script 2. Create an exclude filter and apply it to each profile that you’d like to exclude internal traffic from, using the following setup: Filter Type: Custom➪ Exclude Filter Field: User-Defined Filter Pattern: employees Case Sensitive: No 3. Ask everyone in your office who might access your web site to visit this newly created page from every browser on his or her computer (Internet Explorer, Firefox, Safari, etc.…). Send your coworkers the URL or do it for them at their desks if you have to—it absolutely must happen in order for this to work. Now—at least for the next two years—your internal trafc fi will no longer be reported on by Google Analytics The _setVar function will drop a cookie with a shelf life of exactly two years on each person’s computer. So two years from now you’ll have to have everyone visit that same page again. Other Neat (Advanced) Filters Filters in Google Analytics aren’t all about excluding your internal trafc fi or tracking subdomains. They have a variety of uses to make the data in your profile(s) more relevant for you and your business. There are so many different possibilities available with filters that Wiley Publishing could come out with a book entitled 1001 Google Analytics Filters if they so chose. For Google Analytics 3.0 we’ll show you some examples of advanced filters that many folks have already used for their own profiles and that we think will be of use to you. Writing the Hostname in Front of the Request URI This type of advanced filter goes extremely well when you track subdomains and multiple domains within the same profile. Often subdomains and other Chapter 14n Hacking Google Analytics 229 domains will use the same page names, right down to the file extension. By default, when you’re tracking multiple subdomains and domains, visits and page views on two identically named pages will be lumped together, which means you won’t be able to tell which page of which site received what amount of visits. A filter like this one can help avoid this tracking issue, or it can simply satisfy your curiosity as to which page on which site gets more (or fewer) page views. To set this filter up on your profile, create it exactly as shown in Figure 14-4. What we’re doing here is taking the domain name (the hostname, be it www .yoursite.com orwww.secondsite.com) and forcing Google Analytics to write it immediately in front of the page name (the request URI), so that we can tell which page is from which site when we look at any report in the Content section. Figure 14-4: Writing the hostname in front of the request URI Appending the Source after the Campaign What the advanced filter does in Figure 14-4 is extract data from one dimension and append it onto another dimension. At present there are 37 different filter e fi lds as well as two custom e fi lds that can be used to build multi-step filters (see the very next example). One neat filter that marketers can take advantage of is created when you put the name of the source in front of the campaign. The output of this filter can be in the Trafc fi Sources➪ Campaigns report, and it, in essence, adds an automatic second dimension on that report, freeing up 230 Part IIIn Advanced Implementation the dimensioning drop-downs for a third or a fourth dimension. If that sounds interesting to you, create a filter with the following attributes: Filter Type: Custom Filter➪ Advanced Field A➪ Extract A: Campaign Source➪ (.) Field B➪ Extract B: Campaign Name➪ (.) Output To➪ Constructor: Campaign Name➪ B1 A1 Field A Required: No Field B Required: Yes Override Output Field: Yes Case Sensitive: No Notice that in this filter our constructor is B1 A1, not A1B1. This will write the campaign name first, add a white space, and then write the campaign source after that. If you’d prefer to see those reversed, simply use A1 B1. We highly recommend the space between the two pieces of the constructor e fi ld to make report data look cleaner. Three-Step Filter: Adding Campaign Source, Visitor Country, and Campaign Term to the Transaction ID There are two filter e fi lds—Custom Field 1 and Custom Field 2—that serve as temporary holding cells for data that was created by a filter and that is to be used in another filter. Since there are only two filter e fi lds in an advanced filter, using these custom e fi lds can be an excellent option if you need to combine more data than the default advanced filter allows for. Here in our example we’ll use three filters. The first filter will extract the cam- paign source and the visitor country, and dump this data into Custom Field 1. The second filter will then extract Custom Field 1 (which has campaign source and visitor country data), and also extract the campaign term and dump that data into Custom Field 2. Finally, the third and final filter will extract Custom Field 2 and combine and output it to the Ecommerce Transaction ID. The results of this three-step filter can be viewed within the Ecommerce➪ Transactions report. Filter 1 Filter Type: Custom Filter➪ Advanced Field A➪ Extract A: Campaign Source➪ (.) Field B➪ Extract B: Visitor Country➪ (.) Output To➪ Constructor: Custom Field 1➪ A1 B1 Field A Required: Yes Field B Required: Yes Chapter 14n Hacking Google Analytics 231 Override Output Field: Yes Case Sensitive: No Filter 2 Filter Type: Custom Filter➪ Advanced Field A➪ Extract A: Custom Field 1➪ (.) Field B➪ Extract B: Campaign Term➪ (.) Output To➪ Constructor: Custom Field 2➪ A1 B1 Field A Required: Yes Field B Required: No Override Output Field: Yes Case Sensitive: No Filter 3 Filter Type: Custom Filter➪ Advanced Field A➪ Extract A: Custom Field 2➪ (.) Field B➪ Extract B: E-Commerce Transaction Id➪ (.) Output To➪ Constructor: Transaction Id➪ B1 A1 Field A Required: Yes Field B Required: No Override Output Field: Yes Case Sensitive: No n o t e When working with multi-step filters such as the one in the preced- ing example, it is imperative that the assigned filter order is set, from top to bottom, as we show here. Filters will be processed in the order in which you arrange them, and it could get very nasty if a filter in a multi-step set of filters were out of order. Tracking Google Search Engine Rankings Another excellent use of Advanced Filters is to display the actual position of a key- word within Google’s organic listings in your Trafc fi Sources➪ Keywords report. In April of 2009 Google announced that it would be modifying the way queries are structured within its URLs, which opened the door for this type of filter to be created. (Thank you very much both to André Scholten from Trafc fi 4U for creating the original 1.0 version of this l fi ter, and to Corey Koberg from WebShare, who are both Google Analytics Authorized Consultants, for creating the 2.0 version.) 232 Part IIIn Advanced Implementation We will showcase the two-step filter, which assumes that you are running cost-per-click advertising (with AdWords). There is a single-filter version for non-cost-per-click advertisers, available on the WebShare blog via this link: http://www.websharedesign.com/ display-search-engine-rankings-seo-in-google-analytics.html Filter 1 Filter Type: Custom➪ Advanced Field A➪ Extract A: Referral➪ (\?&)(cd)=(&) Field B➪ Extract B: Campaign Medium➪ organic Output To➪ Constructor: Custom Field 1➪ A3 Field A Required: Yes Field B Required: Yes Override Output Field: Yes Case Sensitive: No Filter 2 Filter Type: Custom Filter➪ Advanced Field A➪ Extract A: Custom Field 1➪ (.) Field B➪ Extract B: Campaign Term➪ (.) Output To➪ Constructor: Campaign Term➪ B1 (A1) Field A Required: Yes Field B Required: Yes Override Output Field: Yes Case Sensitive: No After 24 hours check out your Trafc fi Sources➪ Keywords report and click on the “non-paid” text link above the report table to display only organic keywords. You should start to see keywords with numbers next to them—the number represents the keyword’s position in Google’s search results at the time of the visit(s) to your web site. Tracking PDF (and Other) File Downloads Most web-site owners and Google Analytics account owners do not realize that with a simple JavaScript onClick event you can track any outbound link on your site, as well as any link to a PDF file, an MP3 file, or the link on your big rotating “E-mail Us” graphic on the bottom of your web site. (People don’t still use those, do they?) Chapter 14n Hacking Google Analytics 233 Even if you do still use a large rotating “E-mail Us” graphic on your “Sign My Guestbook” page hosted by GeoCities, that’s OK, because it’s trackable with Google Analytics. Tracking PDF/Downloadable Files as Content On any anchor tag (a) that opens up or downloads a file for one of your visitors when that visitor clicks the text link, you can use the _trackPageview function as a JavaScript onClick event, as shown in this example: a href=”http://www.yoursite.com/white-paper.pdf” onClick=”pageTracker._trackPageview(‘/white-paper.pdf’);” Download a PDF/a After a few visitors have clicked your PDF link, check your Content➪ Top Content report for white-paper.pdf, and you should see some visits listed for it. (In this case “visits” will actually be clicks on your downloadable file). In some situations you may get thrown a scripting error after implementing this onClick event. If this happens you may need to move the standard Google Analytics Tracking Code above this onClick event in the source code, preferably immediately below the opening body tag. Setting Up Goals for Your Downloadable Files The advantage of using the _trackPageview function is that it registers the onClick event on your link as a page view in content reports. Because of this, you can set up this virtual URL as a goal in Google Analytics. Figure 14-5 shows the PDF file from our previous example being used as a goal in a Google Analytics profile: Figure 14-5: Goal Setup for your downloadable (PDF) file 234 Part IIIn Advanced Implementation The goal that we show in Figure 14-5 will match any instance of /white-paper.pdf. But what if you have multiple PDF files scattered through- out your site and you’d like to track any of the views or downloads of all those PDFs as a goal? Well, if you use a smart, consistent naming convention for all your _trackPageview values on all your PDF file anchor tags, you can write a simple Regular Expression to match any PDF download your site has to offer. Let’s pretend for a second that all my PDF files have _trackPageview values of /pdf/name-of-file.pdf. I can set up my goal as follows: Active Goal: On Match Type: Regular Expression Match Goal URL: /pdf/. Goal Name: Anything you want Goal Value: 75 (ALWAYS use a Goal Value for your Goals) After implementation (and after a few days or a week), visit your Goals➪ Goal Veric fi ation report to see a breakdown of which PDF files were viewed or downloaded and counted as goals. n o t e You can also track PDF (and other) file downloads as events, which will have their data populated within the Event Tracking subsection of reports. Please visit Chapter 19 (“Event Tracking”) for examples of doing just that. Customizations with the Google Analytics Tracking Code You can make lots of different types of customizations with your regular Google Analytics Tracking Code. You can track virtual page views, you can track two (or more) Google Analytics accounts simultaneously, you can add your new favorite search engine as an organic source of trafc fi , and you can even turn on data sampling We’ve tried our very best to compile the “greatest hits” in this section. Tracking Virtual Page Views We’ll start right where we left off in the section on tracking downloadable files. Using the _trackPageview function within your Google Analytics Tracking Code is extremely useful for cleaning up long, bulky, SEO-unfriendly URLs. It’s also great for a common situation on the Web in which different web pages share the exact same URL. This happens a lot on confirmation/receipt pages Chapter 14n Hacking Google Analytics 235 (thank-you pages), so using _trackPageview will allow Google Analytics to use another request URI (page name) instead of what it sees in the URL in the browser’s address bar. Using _trackPageview is actually a requirement if your thank-you page shares the same URL as its previous form page. Here’s an example of _trackPageview being used within the Google Analytics Tracking Code: script type=”text/javascript” var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”); document.write(unescape(“%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”)); /script script type=”text/javascript” try var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._trackPageview(); catch(err) /script Tracking Two Accounts Simultaneously Who said Google Analytics can’t track two separate profiles or accounts at the same time? Regardless of what you’ve heard or read before, the Google Analytics Tracking Code can most definitely support tracking two accounts simultaneously—as long as you are careful and set it up properly. In the fol- lowing example we use a declaration of var secondTracker to define our other account’s UA number and _trackPageview function. However, you can use any name you want—joeTracker, jerriTracker, myTracker—as long as it is consistent on all pages of your web site. script type=”text/javascript” var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”); document.write(unescape(“%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”)); /script script type=”text/javascript” try var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._trackPageview(); var secondTracker = _gat.getTracker(“UA-YYYYYY-Y”); secondTracker._trackPageview(); catch(err) /script 236 Part IIIn Advanced Implementation In no time, both accounts should show the same number of page views for your web site. Custom Segmentation (User-Defined) Earlier in this chapter we showed an example that used the _setVar function to set a cookie on a visitor’s computer so that we could block out our internal traf- c fi that used dynamic IP addresses. When you use _setVar within the Google Analytics Tracking Code, the __utmv cookie gets set on the visitor’s machine, which identie fi s the user with the label that you write into the _setVar function. This is helpful for tracking site registrants, shoppers, and other visitors who have performed specic fi actions on your web site. var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._setVar(“shoppers”); pageTracker._trackPageview(); The _setVar function can also be used as an onClick event on a hyperlink, just as with tracking file downloads: a href=”http://www.yoursite.com/admin.php” onClick=”pageTracker._setVar(‘Administrator’);”Administrator/a _setVar can also be used as an onSubmit function, as well as any other JavaScript function, such as for a user submitting a form: form action=”http://www.otherwebsite.com/processing.php” name=”form” method=”post” onSubmit=”pageTracker._setVar(‘interest’);” The data from your _setVar methods is all collected within the Visitors➪ User-Defined report, where you should see the labels that you assigned your _setVar functions across your site. Custom segmentation like this is key for obtaining a deeper understanding of your important visitors and their subse- quent activity on your web site, so learning to embrace the User-Defined report and the _setVar function can only benet y fi ou. Modifying the Session Timeout By default each visitor has 30 minutes to perform an interaction on your web site. If that visitor doesn’t visit another page on your site after 30 minutes, the analytics session will time out and will start again when he or she returns to your site, returns to the computer, or comes back from lunch. This default ses- sion timeout may not work for your web site, as you may have videos and games that take longer than 30 minutes to watch or play—and you wouldn’t want these Chapter 14n Hacking Google Analytics 237 highly-engaged visitor sessions to be timed out. Use the _setSessionTimeout function within your Google Analytics Tracking Code to increase (or decrease) the length of the session timeout. The _setSessionTimeout function uses seconds as its unit of time, and the default in Google Analytics is 1,800 seconds. var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._setSessionTimeout(“5000”); pageTracker._trackPageview(); Modifying the Campaign Conversion Timeout Another editable default setting of Google Analytics is the campaign conversion timeout. Google Analytics will give credit for a conversion/transaction to the most recent campaign data stored in the visitor’s __utmz cookie, if the transac- tion happens within six months (the default lifespan of the __utmz cookie). Your business may have a very long sales cycle, and six months may not be enough for you. Or six months may be far too long, in which case you’ll want to shorten that time span. With the _setCookieTimeout function you can make this happen. Like _setSessionTimeout, _setCookieTimeout uses seconds as its unit of time. To give you a point of reference, 180 days (about six months) equals 15,552,000 seconds. var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._setCookieTimeout(“40000000”); pageTracker._trackPageview(); Modifying Conversion Attribution (Last to First) It’s high time that marketers everywhere received the proper credit for being responsible for generating conversions/transactions to their web sites. Google Analytics uses a last-visit attribution model for conversion data by default, but this can be changed to a first-visit attribution model by way of the utm_nooveride=1 query parameter in your marketing destination URLs. Let’s say that someone visits your site via a Google AdWords ad, but doesn’t make a purchase or doesn’t visit that key page of your site. Then, two weeks later, the same user sees your e-mail newsletter with the same offer as your AdWords ad, and decides to click the link and convert. The conversion credit would go to the newsletter even though (arguably), some if not all of the actual credit for that conversion should go to the AdWords ad that originally introduced the visitor to your site. With utm_nooverride=1 you can give all the credit to the first referring source /medium/term/campaign. 238 Part IIIn Advanced Implementation Simply append the following bolded code to the end of a properly tagged destination URL. You must have the three required URL tagging dimensions in order for utm_nooverride=1 to function properly: http://www.yoursite.com/landing-page.html?utm_source=google&utm_ medium=cpc&utm_campaign=T-Shirts+-+National&utm_term=green+ shirts&utm_nooverride=1 n o t e To learn all about URL tagging please revisit Chapter 13 (“Google AdWords Integration”), where we cover it in great detail. Using the Anchor () Symbol in Destination URLs Speaking of URL tagging, there will be rare cases where your web server won’t accept the use of the? symbol as the beginning of your URL parameter. If your URL-tagged destination pages lead users to an error page because of the query parameters, you can set the _setAllowAnchor method to true and use the symbol instead: var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); pageTracker._setAllowAnchor(true); pageTracker._trackPageview(); Then use the symbol instead of the ? symbol, as in this example: http://www.yoursite.com/landing-page.htmlutm_source=google&utm_ medium=cpc&utm_campaign=T-Shirts+-+National&utm_term= green+shirts Recognizing ‘Nonstandard’ URL Query Parameters Sometimes URLs from other marketing efforts will already be loaded with their own query parameters, and you may not be able to add on additional URL parameters or edit the URL in any way. Not to worry—you can add up to seven different functions within your Google Analytics Tracking Code to detect (and accept) nonstandard dimensions (like utm_source, utm_medium, and so on). Let’s say that you have the following URL: http://www.yoursite.com/email-landing-page.html?id= 12345&effort=Spring%20Sale&source=email&type=corporate&keyword= green%20shoes&link=2&key=98769876 Here, you can see parameters like id, source, and keyword. These query parameters can basically be mapped into your Google Analytics Tracking Code

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.