The code to track an action is actually quite simple, loading prop values and calling the tracking method. Here is what a tracking script looks like. This example is the basic custom click tracking code that you would expect to see in an onclick event attached to an anchor tag. Track. Vars prop. Track. Events None. Televisions. s. prop. WuDFZ.png' alt='Codeigniter Insert Update If Exists Mysql' title='Codeigniter Insert Update If Exists Mysql' />Samsung LN4. B5. LCD TV 1. 08. Full. HD. s. tlthis, o. Now, this is fairly self explanatory, but Ill break this down line for line so you know exactly whats happening and what these statement mean. Track. Vars declares which prop codes you will be using in this event. This property is a comma separated list of each prop code that you want tracked. Track. Events are the events that an action may represent. Usually you will use events like purchase or save but you can put just about anything you want in here. Its just a different way of looking at the same information. I typically set it to none and use custom insights for reports. In this case prop. The tl method a. Links method requires two parameters, this anchor object to be tracked should always be this and the type of link we are tracking. There are three types of basic links that is method understands o is the OtherGeneral link type, d is a File Download link, and e which is an Exit Link. Anything that isnt a download or exit link should be given the o tag. There you have it, not incredibly complex, but not obviously simple either. There are a bunch of other properties that you can attach to a track. Links event, but this is what 9. Building a script to attach link tracking events automatically. There are two standard ways to attach these custom link tracking events to the anchors that you want to track the stupid method, and the smart method. The stupid method is the most common. This involves adding an onclick tag to every anchor and filling it with the appropriate code. Pros Stupid, simple, always works. Cons Stupid, unmaintainable, ugly, increases markup, adds non semantic markup. The smart method is to build a single script that will attach the code to every link you want to track automatically on page load. Pros Smart, not stupid, simple, maintainable. Cons Links dont get the tracking events attached until the whole page has finished loading. For this rest of this article I will assume that you want to use the smart method. Basically, we will build a script that will look at every single anchor tag in the DOM and attach the click tracking events to any links matching whatever criteria you choose. This script will automatically run when the page loads. Defining the criteria and search pattern. First off, you must be able to identify the links that you want to track. I have used two different systems for this Searching href tags and adding rel tags. Searching href tags is generally the best option. This means matching the link href and attaching the event based on that data. However I have found situations where I didnt want to track every link that had the string products. I chose to add rel tags to those links that I did want to track. This way I could just search for links that had relproduct in them. The technique is still basically the same, we will gather all of the anchors in the document into an array, then iterate through the array, attaching the appropriate events and data to those anchor which meet our criteria for each type of page. The basic script structure. No matter what you choose as your search criteria and trackable data you will need a script that has at least the following features Iterates through all anchors on a page. Allows you to attach tracking events without overriding any existing events. Automatically runs as soon as the page loads. Highly optimized for minimum execution time. Cannot throw an error that will break the page. Unobtrusive design that doesnt have any dependencies other than OmnitureNamespaced in object literal notation so that it can never have any confilcts. The basic Java. Script object that I use for this. Omniture click tracking. Links var sbtrack. Links new Object. Links. initialize the click tracking system and attach events. Elements. By. Tag. Name return false. Elements. By. Tag. Namea. for var ianchors. SEARCH STATEMENTS AND TRACKING VARIABLE BUILDING GOES HERE. Codes, link. Type o. Track. Vars. Track. Events None. Codes. Codes. s. link. Track. Vars code, build the CSV list. Codes attach the prop code. Type. non breakingnon overridingcross browser event attachment. Event functionobj, ev. Type, fn, use. Capture. Event. Listener. Event. Listenerev. Type, fn, use. Capture. Event. var r obj. Eventon ev. Type, fn. Type fn. auto init on load. Links. add. Eventwindow, load, sbtrack. Links. init. This is the basic outline of my Java. Script click tracking object. It has three methods and automatically runs itself in the window. Ive put a lot of thought into optimizing this script. For instance, notice that I reverse iterate through the anchors array. This technique has been proven to be faster because the array length is only calculated once when the for statement begins. If you do the while ilt array. When you build any kind of tracking or analytics Java. Script your highest priority should be to shave every nanosecond from its operations. It is acceptable to sacrifice readability for performance here. After all, as a web developer your primary job should be to improve user experience, tracking scripts are a necessity but do not benefit users in any way, so you do your best to reduce their impact on user experience. The sbtrack. Links methods. There are three methods in the sbtrack. Links object initThe init method is where the startup, initialization and event attachment will occur. We still need to build the search criteria, tracking variables and event attachment code before this will do anything.