onclick and filegetcontents... is it possible?

20 replies
Hi,

I am trying to track click-through ratios for the advertisers on my site. The idea is that when a visitor clicks a link (HTML <a tag), an onclick event will fire off a call to another process and increment a counter before opening the link.

<a href=http://www.anyurl.com/ target="_blank" onclick="filegetcontents('http://www.specificurl.com/filename.php');">Anchor Text</a>

In this way I can count the number of times somebody clicked on a specific link.

To my understanding, this should first call 'specificurl', and then open 'anyurl' in the browser. But I can't seem to get it to work. Can anybody see an obvious syntax error?

Is this even possible?

Is there a better way to accomplish this? I have to do it in an SEO friendly way, followable by search engines.

To complicate matters, this link may not live on my URL so I cannot depend on any include statements etc.

Thank You in advance for your help!
#filegetcontents #onclick
  • Profile picture of the author SecureWeb
    This can be achieved pretty easily with embedding a 1X1 iframe on the page, and then using the onclick to fire a javascript function that can load any url into that iframe.

    Since you are opening the click in a new window/tab it will work everytime. I do something like this for tracking optins.

    Hope that helps
    {{ DiscussionBoard.errors[2098834].message }}
    • Profile picture of the author Damien Roche
      If I read you right, you should be able to do this via ajax.

      I did it on a salespage once to determine which buy button the 'buyers' were clicking on.

      It is fairly simple but you need to explain more.
      Signature
      >> Seasoned Web Developer (CSS, JavaScript, PHP, Ruby) <<
      Available for Fixed Fee Projects and Hourly ($40/hr)
      {{ DiscussionBoard.errors[2099079].message }}
      • Profile picture of the author RokNStoK
        Hi Damien, Thank you for your suggestion! Can you tell me what considerations there are for using Ajax?
        1. Licensing
        2. Development Software
        3. Learning Curve

        I don't necessarily want to learn Ajax... I just want to accomplish this specific task.

        The Task Restated: I would like to know when a visitor to my site has clicked a specific link. The tracking should be transparent to the visitor and the new window/tab should open as one would expect when clicking a link. The original window on which the link was clicked should remain intact.
        As part of the tracking task, I have to initiate a process behind the scenes to write to the database. The logic to do so is already written as a PHP file. I just need to call that file 'onclick'.

        Crap! I can't say anything without sounding like a robot!

        Let me know if you have any questions... Thanks for your help!
        Signature
        Ken
        www.monopolinks.com
        Free One-Way Link Exchange
        {{ DiscussionBoard.errors[2100223].message }}
        • Profile picture of the author SecureWeb
          I was just going by your example link and saw the target="_blank" there.

          If you can't open a new window, then you will need to use some sort of tracking... like a php or perl script/redirect, or even a sandwich page that just fires a pixel or javascript tracking code, then redirects to where ever it's supposed to go.

          IMHO, AJAX is over kill, and way more complicated.

          Or, if you are not worried about SEO, you can frame your site in a 100% frame, and add a hidden frame that all your javascript calls point to... it will work just like the iframe method, except no new windows/tabs opened...

          Oh, and another method... You can do the 1x1 iframe on the page... and load a sandwich page (contains tracking pixels or javascript), and have that refresh using a meta refresh, or javascript top.location.href to the url of choice.
          {{ DiscussionBoard.errors[2103864].message }}
    • Profile picture of the author RokNStoK
      Hi SecureWeb and thanks for your quick response! I actually do not want to open a new URL from the onclick event. The href=URL is the one that should be opened in a new browser/tab. The URL in the onclick event should only initiate a process that updates the database.

      Everything I'm hearing indicates that it's not going to work to mix javascript and PHP... correct? I like your idea. I've never worked with Iframes before... but it doesn't sound that complicated. Would it be possible to open a url in the iframe and NOT have it open? The process doesn't have to generate any output... but it can.

      Thanks for your suggestion!
      Signature
      Ken
      www.monopolinks.com
      Free One-Way Link Exchange
      {{ DiscussionBoard.errors[2100190].message }}
  • Profile picture of the author Manfred Ekblad
    Are you still working on this? Got it working?
    {{ DiscussionBoard.errors[2104597].message }}
    • Profile picture of the author RokNStoK
      Good Morning Manfred,

      Still not working. I am figuring out that I'm not going to be able to combine javascript and PHP... Something about calling server side script with client side script... seems like a silly limitation to me

      I've had suggestions for Ajax, Iframes... and possibly more. I don't think any will accomplish the task as I need it to be (in an SEO friendly way). There was Ajax which supposedly will work, but seems like a big learning curve for this 'non-mission critical' task.

      If you have another suggestion, I'll be happy to give it a try! Please let me know if you would like me to restate the problem! Thanks Manfred!
      Signature
      Ken
      www.monopolinks.com
      Free One-Way Link Exchange
      {{ DiscussionBoard.errors[2104906].message }}
  • Profile picture of the author Manfred Ekblad
    Just guessing, but I think what you want is a SEO friendly way of tracking clicks on your links.

    Three questions:

    1. The link is on page A and goes to page B..?
    2. The visitor on page A click on the link, the click is counted and the visitor end up on page B..?
    3. You can edit page A but you don't have access to edit page B..?

    Let me know, I'm sure we can figure it out
    {{ DiscussionBoard.errors[2105318].message }}
    • Profile picture of the author RokNStoK
      Hi Manfred,
      Everything you stated is correct with the exception of #3. I'm not sure what you're saying there.

      The only other thing I would add is that If you click the link on Page A, then Page B should open in a new window (optionally).

      Thanks again for your help Manfred! Please remember this is a 'forward looking project' for me... there is no rush. Thanks again!
      Signature
      Ken
      www.monopolinks.com
      Free One-Way Link Exchange
      {{ DiscussionBoard.errors[2105781].message }}
  • Profile picture of the author Manfred Ekblad
    With #3, I mean...

    ...can you edit page A?
    ...can you edit page B?

    If you can edit both of them, thats great.

    You need to have access to the page with the link (page A), thats the minimum requirement, otherwise you won't be able to update the html/javascript/php code at all
    {{ DiscussionBoard.errors[2105924].message }}
    • Profile picture of the author RokNStoK
      Hi Manfred.
      I have access to A... but not full access. I won't be able to depend on an 'include' statement.

      I don't have access to B at all. This is the 3d party destination (advertiser)

      There is a script C also that I've already written. Called with a few parameters, it will update the database(so our solution should be able to pass parameters). It should be called when the link on A is clicked.

      Make sense?
      Signature
      Ken
      www.monopolinks.com
      Free One-Way Link Exchange
      {{ DiscussionBoard.errors[2106422].message }}
  • Profile picture of the author Manfred Ekblad
    Yes!

    How much access is "not full access"?

    Can you use PHP code or are you limited to HTML/Javascript?

    Either way, I've got a solution for you...
    {{ DiscussionBoard.errors[2107023].message }}
    • Profile picture of the author RokNStoK
      Hi Manfred!
      One requirement for the host site (site A) is that I'm allowed to use PHP. I'm actually less familiar with javascript, but what little I've tried usually seems to work.

      Thanks Manfred! Can't wait to hear your solution!
      Signature
      Ken
      www.monopolinks.com
      Free One-Way Link Exchange
      {{ DiscussionBoard.errors[2107256].message }}
  • Profile picture of the author AlTheGr8
    I would personally approach it a bit differently. I would use link cloaking. So, instead of creating a direct link to some Web site. I would link to a page on my own site. That would increase the counter and redirect to external URL. This is how it is done on most of the sites. Gives you better control too.

    Good luck.
    {{ DiscussionBoard.errors[2108879].message }}
    • Profile picture of the author RokNStoK
      Hi AlTheGr8,
      Thanks for your suggestion. One requirement I cannot compromise on is the SEO aspect of the link. The page from which the link is clicked must be the page that is credited with the link (by the SE's). In the case you have laid out, the page would be credited with a link to me instead of the true destination site.

      Thanks again for your suggestion!
      Signature
      Ken
      www.monopolinks.com
      Free One-Way Link Exchange
      {{ DiscussionBoard.errors[2109054].message }}
  • Profile picture of the author Manfred Ekblad
    AlTheGr8, I agree that usually that would be the way to do it. However, the requirements for this issue is a bit "unusual" if I've understood it correctly. Actually, I'm currently working on a product for link cloaking, but in this case something else needs to be done.

    By the way... for those who are interested, here is some information about search friendly redirects:

    http://www.seoworkers.com/seo-articl...redirects.html

    http://www.theinternetdigest.net/arc...rects-seo.html
    {{ DiscussionBoard.errors[2109285].message }}
  • Profile picture of the author AlTheGr8
    Ken, Manfred, you guys are correct, I missed that in the original message. In this case I would just use Google Analytics. Most people don't know this but it is actually capable of tracking outbound external links. More on this here - How do I manually track clicks on outbound links? - Analytics Help
    {{ DiscussionBoard.errors[2109338].message }}
  • Profile picture of the author Manfred Ekblad
    Yeah, the solution I'm thinking of is similar to Googles tracking, but of course using the counter that has been mentioned already, so it needs custom code...

    ...unless Google's click tracking is enough in this case?
    {{ DiscussionBoard.errors[2109393].message }}
    • Profile picture of the author RokNStoK
      Hey Manfred and AlTheGr8,

      I'm familiar with the analytics tracking... not going to work in this case because I don't own site A... on which the link resides.

      To clarify, I have a link exchange. One feature of the exchange is an 'automated link publishing' feature that publishes the 'links page' on the member website.

      This is accomplished by the member uploading a small PHP file to their site. This file uses filegetcontents to call another URL, C on my website that will automatically generate the pages, return the HTML to the calling site which will display the dynamically generated links pages. Clear as mud?

      It's on this dynamically generated page that link A exists. If a visitor to the member site clicks link A, I would like it to open the destination link, and then notify the monopolinks system that link A has been clicked. In this way, I can tell how much traffic any given member gets from any other given member through the AutoLinks system.

      Is it possible? Thanks Guys!
      Signature
      Ken
      www.monopolinks.com
      Free One-Way Link Exchange
      {{ DiscussionBoard.errors[2111187].message }}

Trending Topics