The content filter function that is put in place by calling add_filter receives the entire content of all the posts and pages before they are rendered to the browser and is allowed to make any number of changes to this information. In this case, we are using the PHP str_replace function to search for any occurrence of the string href, which indicates a link. When the string is found, it is replaced with a call to a JavaScript function as well as the original href tag.
To make this plugin complete, it also needs to provide an implementation for the JavaScript recordOutboundLink function. This is done by registering a custom function with the wp_footer hook that will output extra content with the function code in the website's footer.
The resulting plugin automates many of the tasks related to tracking usage data on a website using Google Analytics.