Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Click tracking with Javascript (recording outgoing links)

Avatar of hbkmunroe
hbkmunroe asked on
JavaScriptInternet MarketingAJAX
11 Comments1 Solution602 ViewsLast Modified:
Can someone tell me the best way to track outgoing links from my site?

I have a set of affiliate links that I want to record. I'm currently using this Javascript script:

//record stats
function clk(id){
      var trackImg = new Image()
      trackImg.src = "/record_stat?id="+id;
      return true;
}

And the link calls the following:
<a href="http://www.google.com" onmousedown="return clk('1')">Link</a>

Now this works fine on my local host but when I put it live on server it only works the odd time.

Must be something to do with the page following the href location before creating the JS image (I think) but what is the best way to do it? (I think this is even the way Google tracks links)

Thanks for your help.
ASKER CERTIFIED SOLUTION
Avatar of Cem Türk
Cem TürkFlag of Turkey imageSenior Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answers