0

The link is a text field that's value is pulled directly in node.tpl:

<a class="list-parent-link" href="<?php echo $node->field_download_link['und'][0]['value']; ?>">

I'd like to be able to track how popular each node's link is, and display the 5 most popular nodes in a views block. Is that possible?

1

1 Answer 1

0

yes it can be done in a number of ways... some options:

1) add a JS onclick="" to the link which goes to a function that causes an ajax call to the server. The server would then take in node information and using something like the Flag Module:

Flag is a flexible flagging system that is completely customizable by the administrator. Using this module, the site administrator can provide any number of flags for nodes, comments, users, and any other type of entity. Some possibilities include bookmarks, marking important, friends, or flag as offensive. With extensive views integration, you can create custom lists of popular content or keep tabs on important content.

to trigger a counter which can then be easily used in Views.

2) adjust the link direction to an internal proxy page:

<a href="/mymodule/proxy?url=<?php echo $node->field_download_link['und'][0]['value']; ?>">

The proxy page would have a callback function that again uses Flag or similar to track the click and then redirect the page to the provided url.

Option 2 is probably the better of the two, but it depends on the set up, and whether or not you want a redirect, etc.

I can give more specific guidance if you decide to go with one of these.

4
  • I've been meaning to take you up on this. This is a side project and I've been jumping around on different issues that need solving. Which of these two would scale better? I don't mind redirecting.
    – James
    May 27, 2015 at 19:40
  • if you're comfortable with a redirect (left as a blank white page, the end user may not even realise a redirect was made) then the second option is much simpler, and easier to manage long term
    – Geoff
    May 27, 2015 at 20:35
  • It definitely sounds easier to manage. Where do I start?
    – James
    May 27, 2015 at 21:24
  • 1) create a custom module 2) create a page callback using hook_menu() 3) modify your links to include the redirect, including current node information (href="/custom_external_link_analytics?node=<?php echo $node->nid; ?>" for example) 4) create the page callback and use the flag API to flag that particular node (now that you have been provided node information) - with the VOTE API, you can use flag to count the times a node is flagged. 5) use views with a relationship to the flag to show the content however you want - work one step at a time and a simple search should yield the details
    – Geoff
    May 28, 2015 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.