using drupal 4.7.4
statistics module to obtain hits

I am trying to figure out how to make a link do 2 things:

1) register a hit for the particular node (this part obviously works)

2) but instead of going to the full body of the node, I want it to go to an external site.

So for instance, a user posts a node that contains a link to an external site. I basically want other people to be able to go to this external site, but allow for hit counting to take place . Since I use the full node, I don't have a need to go to the full node listing, so I am trying to elminate as many clicks as possible.

I am doing a template for this content type, so I was really hoping for some sort of code I could put into the link (kind of like how the add to cart links work) but I am probably asking for something that is way beyond me (what a shock) :P

Anyone have any ideas on how I could do something like this?

Comments

quaestor’s picture

What sort of nodes are you dealing with exactly? Actual Weblinks, Links, or CCK? Custom?
The way you describe it, are the links stored in the node body?

What I personally did to solve this problem was to create a function in that 'lives' at http://mysite/count
Anytime a link was displayed, it would actually display as http://mysite/count/nodeid. When it's clicked the counter function tracks the click and then forwards the browser onto the real link. But I made a custom module for a specific content type so this might not work for you.

If this seems useful to you let me know and I'll post more details.

There is also Click Through Tracking at http://drupal.org/node/36916 . I don't know if it would help in this case. It seems to be more for external referals?

solidad’s picture

Your module sounds pretty close to what I am looking for...not really sure though. I am also looking at this module: http://drupal.org/project/gotwo But it just doesn't look right for some reason. The thing that frustrates me the most is that there can be so many different ways to approach a situation that, you get lost between choosing a module, using pieces of a module, or writing something custom...and then of course there is always the external applications..but anyway....

I used CCK to create the node. it has the following fields (as an example i'll just keep it really shor)

Title (default node title...obviously required)
Website Address (single line text field...nothing special..full url used)

I used phptemplate to make a new template for this node. here is the snippet a code so you can see what I did.

<a href="<?php print $field_website_address[0]['value'] ?><?php print $node->title ?></a>

As you should be able to see, I took the title of the node and made it the title of the website address. There is no link at all to the full node body in the entire node.

I tried to use "destination" to maybe get drupal to register that the node was clicked on, but the ending destination would have been the external site.

<?php print $field_website_address[0]['value'] ?>?destination=/node/<?php print $node->nid ?>"><?php print $node->title ?></a>

but that generates a url of www.site.com/?destination=node which of course, isnt correct either. I hope my long winded description isn't too confusing. Thank you very much for trying to help. I hate how simple a concept sounds, but the steps to achieve that concept seem either huge, or endles. :P

quaestor’s picture

Someone more knowledgeable might give a different answer than mine but here goes...

I'm not aware of any direct way for drupal to send a browser on its way while also registering a click. I'm fairly certain you need to specify a local link that accesses some kind of counting function before seamlessly sending the browser to the correct site.

http://drupal.org/node/28111 has a break down of how the Web Links module can do this. :) This is more or less what I did in my own module. Like you say, it's hard to decide to reuse a module or create your own.

Frankly, I think there may be lots of situations like this where it might not make sense to implement an entire module. I'm starting to collect enough little one-off functions like this that I'm on the verge of creating a misc module with lots of functionality that just doesn't fit anywhere else. Maybe this is something you should look at as well? However, keep in mind I'm still learning this stuff. A more advanced Drupal developer might scream in horror at what I just typed.

Anyway, does that help? I'm not sure I actually answered your question.