Instant Article Directory

Click-Tracking Hyperlinks

Coding 
[222 Clicks]

Content

Click-Tracking Dynamically-Generated Hyperlinks From MySQL Databases

I recently almost lost my mind trying to step up my applications' game. As a "content links" purveyor, it's a great mechanism; rapid operation, smooth process-flow (submission, editing, etc.), but it was lacking a proper tracking method for the ability to display the real-time, click-through statistics that even a casual visitor could view. As a fan of coding, I was sure it was a lickety-split operation. A quick search engine ride yielded an interesting return from jQuery;

< script type="text/javascript" >
$(document).ready(function() {
// BEGIN redirect all outbound links through tracker page
$("a").click(function(){
// if it's a full URL...
if ($(this).attr("href").indexOf("http")==0) {
// if it doesn't go to our site
if (!/^http(s){0,1}(.){0,3}(www){0,3}(\\.){0,1}promodrone\\.com/.test($(this).attr("href"))){
// send it through the linkout page
$(this).attr("href","/LINKOUTPAGE.PHP?p=" + $(this).attr("href"))
}
}
})
// END redirect all outbound links through tracker page
};
< /script >

This didn't work out for me...and then I found a BETTER answer to this (lol!)

So, anyway, I got frustrated with the jQuery avenue since fundamentally it wasn't going to help me with the database interaction process needed to record the clicking of the database-stored hyperlinks. And, on top of that, I had another HUGE problem which would actually be the key to the whole solution: the hyperlink itself. As I wasn't understanding the fact that most of the link click-tracking script solutions require you to manually enter your hyperlink destinations so that the script only has to record the click on CONVENTIONAL URL schemes (http://, https://, ftp://, etc.). When handling database display of information, the most expedient (and well-documented) way is with PHP, as the hyperlink values can be output as variables (represented by the $ sign). Mine was shaped like this:

< a target="_blank" href="< ?php echo $link;? >"< ?php echo $title;? >< /a >

WHAT AM I SUPPOSED TO DO WITH THAT?!?!?!?!?! NONE of the solutions in the fifteen-plus scripts and countless code examples that I had garnered were even close to what I needed to take care of this problem. I wanted to keep the structure of the traditional hyperlink so the user had the option of being able to stay and browse while reading the interesting story on its' original page. But I also needed to be able to track the clicks on a dynamically-generated hyperlink while still allowing the hyperlink to fetch the relevant data from the appropriate database table. I was stuck for a few days when I decided to switch the search query language to include the notion of database-driven link display. It didn't take more than a few, scope-narrowing searches to determine my best course of action. Combining the concepts of concatenation and interpolation, I was able to not only work out how to to track clicks on dynamically-generated hyperlinks, but also how to retain the traditional hypelink behavior to preserve site-flow. After working through this mentally-exhaustive process, displaying results was a cakewalk;


Cakewalk display in action...


This solution co-incides with the true understanding of database-driven site code interaction after a decade-long investment in study. I hadda construct that code from mastery of the concepts formerly referred to. Note To Self: PDO classes begin immediately.....

AUTHORS' BOX

Mr Lee Davis is the owner/admin of Promodrone.com, an instant publishing site for news, articles, information, multimedia, and infographic submissions along with exposure to profitable opportunities associated with content creation. Are you a content creator in need of an original way to generate laser-targeted buyer visitor traffic to your product and affiliateship salespages? Info can be found at the salespage. As a Web Developer and Writer with thirty-plus years of experience within both disciplines, Mr. Davis is currently freelancing other MMO-based ideas as well as the attendant eCourse connected to his personal info-product.