Hello, I have installed the module and configured:

1. Set permissions for users.
2. Configured Home » Administration » Configuration » Web services » External Link Popularity
3. Create a node with a Link type using the Link module.
4. Using Framework theme I have updated node.tpl.php with:
<div id="node-<?php print $node->nid; ?>" class="node"> at top, closing with

at bottom. This adds <div id="node-2" class="node"> as example in my HTML page.
5. Confirmed that the .js is loading with the page.

Tried to record link clicks, but the database is still empty. Checked pop_links_stats and has zero rows.

I have switched to Garland theme, and still not luck.

Any ideas?

Thanks,
Tim

Comments

hejeva’s picture

Did you make sure permissions are set so anoymous and/or authenticated can "Record external clicks"?

nkschaefer’s picture

Status: Active » Fixed

Sorry it took me so long to respond. I'll look into this to see if there's anything strange going on, but I think there's probably a simple solution: the module (like the Drupal 6 version of it) is set not to track user with ID 1 (the admin/webmaster), regardless of roles and permissions. I ran into this and was confused by it too when I first started working on porting the Drupal 6 version to Drupal 7, and I can try to come up with a way to make it clearer that user 1 won't be tracked, or add a checkbox to the settings form to allow user 1 to be tracked.

As for the markup you need to track a node, you have the right thing. I've made the Drupal 7 version more flexible (it now uses Javascript settings), so I might introduce a hook sometime soon where custom modules can specify what classes/IDs should look like when tracking clicks in a node body.

Please let me know if you're still encountering problems.

Tim Jones Toronto’s picture

Hi, I did check permissions and wanted to confirm that i was doing things correctly.

I will re-test it again from scratch and report back any problems :)

Thanks for your update!

Tim

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

scuba_fly’s picture

ever fixed this? I'm having an similar problem.

therobyouknow’s picture

I have an interim solution that seems to work ( after using it, admin/reports/pop_links shows the links )

this solution is theme dependent on bootstrap as it uses the .btn-success class. Ultimately we want to move to a theme independent solution and one which uses Drupal.behaviours rather than jquery directly. Then I will submit a patch for this module.

( Credit and thanks to Clive for providing a robust way to access the Drupal node id for a page here: http://drupal.stackexchange.com/a/78667/1082 )

// at line 72: in pop_links.module of pop_links module folder (additional args and some code tacked onto end)

// added additional arguments:  $view_mode, $langcode
function pop_links_node_view($node, $view_mode, $langcode) {
  $node_types = variable_get('pop_links_node_types', array('page'));
  global $user;
  if (in_array($node->type, $node_types) && arg(0) != 'admin' && _pop_links_track($user)) {
    $setting = array(
      'pop_links' => array(
        '#node-' . $node->nid => array(
          'nid' => $node->nid,
        ),
      ),
    );
    drupal_add_js($setting, array('type' => 'setting'));
    drupal_add_js(drupal_get_path('module', 'pop_links') . '/pop_links.js');
  }

  // new code here:
  if ($view_mode == 'full') {
    $setting = array('pop_links' => array('currentNid' => $node->nid));
    drupal_add_js($setting, 'setting');
  }
}

in pop_links.js (much commented out -the root cause seems to be that the original jquery/javascript code wasn't firing)

Credit to colleague Andy for some lightening fast Jquery coding:

(function($){


   Drupal.behaviors.pop_links = {};
  
  Drupal.behaviors.pop_links.attach = function(context, settings) {

    console.log('attached', context);


    jQuery('.btn-success').click(function(){
      

    // an external link has been clicked
    var args = {};
    args.operation = "track_click";
    // get the URL of the site the user is going to
    args.url = $(this).attr('href');
    // get the id of the node that contains the clicked link

    // credit: http://drupal.stackexchange.com/a/78667/1082
    // depends on: function pop_links_node_view in pop_links.module
    args.nid = Drupal.settings.pop_links.currentNid;

    // call the popular links AJAX handler
    var rsp = $.ajax({
      data    : args,
      url     : Drupal.settings.basePath + "pop_links/handle",
      type    : "get",
      datatype: "html",
      async   : false // make sure vote is cast before sending user on her merry way
    }).responseText;


      return false;
    });

    // Strip the host name down, removing subdomains or www.
    // var host = window.location.host.replace(/^(([^\/]+?\.)*)([^\.]{4,})((\.[a-z]{1,4})*)$/, '$3$4');

    // // Build regular expressions that define an internal link.
    // var internal_link = new RegExp("^https?://([^/]*)?" + host, "i");

    // if (Drupal.settings.hasOwnProperty('pop_links')) {
    //   for (var selector in Drupal.settings.pop_links) {
    //     var nid = Drupal.settings.pop_links[selector].nid;
    //     $(selector).find('a:not(.pop_links-processed)').each(function(el) {
    //       try{
    //         var url = this.href.toLowerCase();
    //         if (url.indexOf('http') == 0 && !url.match(internal_link)) {
    //           $(this).data('nid', nid);
    //           $(this).click(PopLinksTrackClick);
    //         }
    //       }
    //       // IE7 throws errors often when dealing with irregular links, such as:
    //       // <a href="node/10"></a> Empty tags.
    //       // <a href="http://user:pass@example.com">example</a> User:pass syntax.
    //       catch(error) {
    //         return false;
    //       }
    //     }).addClass('pop_links-processed');
    //   }
    // }
  };

})(jQuery);
therobyouknow’s picture

Wee correction on comment number 6:

I think the

   return false;
    });

is extraneous in the above js. Being present it causes the link to not open - you stay on the same page.

I'll confirm tomorrow. Try removing it yourself if you saw the problem yourself.

therobyouknow’s picture

As promised, this is the corrected pop_links.js code (from above in comment 6 and discussed in comment 7) to use with the php code alterations for pop_links.module as described in comment 6. Enjoy and feedback.

(function($){


   Drupal.behaviors.pop_links = {};
  
  Drupal.behaviors.pop_links.attach = function(context, settings) {

    console.log('attached', context);


    jQuery('.btn-success').mouseup(function(){
      

      $(".field-type-fivestar").addClass("ratelightbox hide fade");
      $(".field-type-fivestar").attr("tabindex","-1");
      $(".field-type-fivestar").attr("role","dialog");
      $(".field-type-fivestar").attr("aria-hidden","true");

      $('#ratelightbox').lightbox(true,true,true);

      // an external link has been clicked
      var args = {};
      args.operation = "track_click";
      // get the URL of the site the user is going to
      args.url = $(this).attr('href');
      // get the id of the node that contains the clicked link

      // credit: http://drupal.stackexchange.com/a/78667/1082
      // depends on: function pop_links_node_view in pop_links.module
      args.nid = Drupal.settings.pop_links.currentNid;


      // call the popular links AJAX handler
      var rsp = $.ajax({
        data    : args,
        url     : Drupal.settings.basePath + "pop_links/handle",
        type    : "get",
        datatype: "html",
        async   : false // make sure vote is cast before sending user on her merry way
      }).responseText;

    });

    // Strip the host name down, removing subdomains or www.
    // var host = window.location.host.replace(/^(([^\/]+?\.)*)([^\.]{4,})((\.[a-z]{1,4})*)$/, '$3$4');

    // // Build regular expressions that define an internal link.
    // var internal_link = new RegExp("^https?://([^/]*)?" + host, "i");

    // if (Drupal.settings.hasOwnProperty('pop_links')) {
    //   for (var selector in Drupal.settings.pop_links) {
    //     var nid = Drupal.settings.pop_links[selector].nid;
    //     $(selector).find('a:not(.pop_links-processed)').each(function(el) {
    //       try{
    //         var url = this.href.toLowerCase();
    //         if (url.indexOf('http') == 0 && !url.match(internal_link)) {
    //           $(this).data('nid', nid);
    //           $(this).click(PopLinksTrackClick);
    //         }
    //       }
    //       // IE7 throws errors often when dealing with irregular links, such as:
    //       // <a href="node/10"></a> Empty tags.
    //       // <a href="http://user:pass@example.com">example</a> User:pass syntax.
    //       catch(error) {
    //         return false;
    //       }
    //     }).addClass('pop_links-processed');
    //   }
    // }
  };

})(jQuery);