We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32507
    • 142 Posts
    Hi,

    We need to have "Most popular pages" -section to our website.

    For example Hits -extra works for MODX resources, but we also need to count clicks to external website (blog-posts).

    Somehow we need to count <a href=""> -clicks to custom database table. I'm trying to figure the easiest solution and came up with the idea to target all links to weblink -resource first, where we change dynamically weblink and pagetitle -fields based on link attributes.

    Current link
    <a href=”https:/www.somesite.com/lorem_ipsum.html”>Lorem Ipsum</a>


    To this
    <a href=”[[weblink-to-external-page]]” rel=”https:/www.somesite.com/lorem_ipsum.html”>Lorem Ipsum</a>


    Step 1: Pass link attributes (rel -> pagetitle, href -> weblink) to weblink-resource fields.
    Step 2: Insert pagetitle and weblink fields to custom table. (+ Add click count) Before redirect to external page.
    Step 3: To retrieve data from custom table and order results based on "clicks" count.

    Is this sounding too complicated? I haven't figured any other way to do this?

    (See the attachement to get better picture.)
    https://drive.google.com/file/d/1pQzNuVrXcwRmXzzQpVN9xhUeHFEjPvXX/view?usp=sharing

    This question has been answered by wintertribe. See the first response.

    [ed. note: wintertribe last edited this post 6 years, 3 months ago.]
      • 3749
      • 24,544 Posts
      Another way to go might be to add a JS onClick() event to each image with an identifier for the image as an argument.

      In the JS function, you'd use Ajax to call a MODX processor that records the click in the DB (not as difficult as it sounds).

      The HTML code would look something like this (assumes that the image ID is in the image_id TV):

      <img src="url/of/image" onClick="handle_click([[*image_id]])" />

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 32507
        • 142 Posts
        Quote from: BobRay at Jan 12, 2018, 05:29 PM

        In the JS function, you'd use Ajax to call a MODX processor that records the click in the DB (not as difficult as it sounds).

        Do you have some example how to implement this? I remember i have struggled with MODX processors sometimes before smiley
        • discuss.answer
          • 32507
          • 142 Posts
          Quote from: wintertribe at Jan 15, 2018, 08:37 AM
          Quote from: BobRay at Jan 12, 2018, 05:29 PM

          In the JS function, you'd use Ajax to call a MODX processor that records the click in the DB (not as difficult as it sounds).

          Do you have some example how to implement this? I remember i have struggled with MODX processors sometimes before smiley

          Nevermind. Had to dig it a little bit, but now I got it smiley

          Thanks!