简体   繁体   中英

Designing a simple system to track the number of times links have been clicked

I've been having a think about how to track and count the number of clicks within my Meteor application.

I have a list of links to externals sites and I want to count how many times they have been clicked. The link should open within a modal / iframe so the user isn't redirected away to the external site. I would create an option on the modal for the page to be opened in a new window/tab.

The only solution I have come up with so far is using a link containing a hashid hashid=sdfkljn24krj23n, checking the hashid against the db and the return the corresponding URL from the db which would then be opened within the modal/iframe.

For creating the hashids I was thinking of using hashids.node.js

I can see doing it this way could get complex on the db as I would need to store the userid, the number of clicks per website, the hashids. I'm likely to have many hash ids to one url so I can track clicks for multiple users.

I just want to create a basic report that has simple data:

user | number of clicks 
a    |        1
b    |        5
c    |        3


Total number of users | Total number of clicks
        3             |           9

Does this approach sound ok?

Simple solution using jQuery:

$('a').onclick(function (event) {

  // Get the current user, however you’re currently tracking that:
  var user = App.getUser();

  // Get the URL of the link that was clicked, by parsing your HashId:
  var url = App.parseHashId(event.target.href);

  // Update the UI with the new click counts:
  App.updateClickCounts( user, url );

  // Save this information to the server:
  $.post(App.getServerURL(), { user: user, url: url }, function ( data ) {
    // Optional: do something on success
  };
});

And depending on your app, write getUser , parseHashId , getServerURL and updateClickCounts functions as appropriate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM