As Webmasters, we often come up against HTML websites that have a large number of pages that need to be optimized. One of the first things to be done is install your Google Analytics tracking code to each page, and when you have a 50 plus page website, that can be extremely time consuming and tedious. Thankfully, there are a few tricks we can use to drastically cut down on the time it takes to go into the back end of each page and input the tracking code.
Ctrl H, your new best friend.
Most of you are probably familiar with Ctrl F, which is the “find” command that allows you to input a word or phrase, and search the page you are on for any occurrences of that particular term. Well Ctrl H, is similar to this function. It is the command for “Find and Replace”, which allows you to do just that, find a certain word, phrase or punctuation, and replace it with pretty much whatever you want. This is the best trick we have to reduce the time it takes to install your analytics tracking code on your HTML website. It allows us to add the code to multiple pages simultaneously.
How it’s done:
The first thing you’ll want to do is open all your web page html files in an html editor, for example Coffee Cup, or Code Lobster. You can open as many files as you want, but I prefer to do it in batches just to make sure I’ve done everything correctly as I go.
Once you have all of the html files open, look in the header section and find the header close tag, </head>. Highlight this tag and then hit Ctrl H, for find and replace. Or you can hit Ctrl H without highlighting anything, and type </head> in the box labeled “Find:”.
Then in the “replace with” box, copy your Google analytics HTML tracking code, followed by the </head> tag. It is imperative that you include the close header tag; this will ensure that the header section is defined as well as ensuring that the code is placed within the header of the html file.
Then on the bottom there will be an option called “Find In:” the default selection is “current document”, switch this to “all open documents”, to enable the replacement on all your html files. Then all you have to do is click “replace all” on the right hand side, and you’re analytics code will be inserted into the header section of each file!
Be sure to click “save all” in your HTML editor before you close any of the files.