We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20339
    • 11 Posts
    MODx’s current stats are great. But they only seem to track "web" pages served by MODx.

    I would also like to track the number of times that users download a file (eg, a PDF) for which I provide a link such as

    <a href="path/to/file.pdf">file.pdf</a>

    User’s clicking on that link somehow "bypass" MODx, and so of course it doesn’t track those clicks.

    Is there perhaps some quick PHP code that I can wrap that link in so that MODx knows the file’s been downloaded?

    Thanks,
    --Michael
      • 4041
      • 788 Posts
      I think you could make a weblink which would do what you require. Then just add your link to a page, and when someone clicks the link it will appear in the stats.
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 20339
        • 11 Posts
        Quote from: breezer at Aug 21, 2006, 10:44 PM

        I think you could make a weblink which would do what you require. Then just add your link to a page, and when someone clicks the link it will appear in the stats.

        That would work. But for a page that may have many (10s) file links, it would be *very* tedious to go through MODx’s manager to add a weblink for each file, and then for each such page.

        But perhaps there’s a PHP snippet that would give the same effect?

        --Michael
          • 4041
          • 788 Posts
          I’m not sure if there are any snippets which do this, you’ll have to search the repository and see whats available.

          Another way you could do this, for example:

          For each document which contains the pdf links, create a folder in an unpublished area of the doc tree. Add all your weblinks which are associated with the document to this folder, then on the page you want to show the items, use one of the menu snippets to list the folder contents.
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I think you could get the FileDownload snippet to do what you have in mind.

            http://www.modxcms.com/FileDownload-502.html
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 20339
              • 11 Posts
              I’ve come around to the idea of using weblinks to to link to files. It’s straightforward and flexible (eg, I could use DropMenu to list the files).

              This raises a question: Can I use chunks in the Weblink field to reference the address of the link? For example, I would like to fill in the Weblink field as

              {{DownloadBaseURL}}/foo.pdf

              This has the advantage that
              - I don’t have to type a long URL each time
              - I can change the location of the files and only need to update the chunk.

              I’ve tried this, but it doesn’t work. Are chunks not interpreted in these fields?

              Thanks!
              --Michael
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                If you look at the code for dealing with a document of type "reference", you see that all it does is take the content of the doucment and immediately redirect the user to whatever URL the content is.
                	
                // check whether it's a reference
                    if($this->documentObject['type']=="reference") {
                    $this->sendRedirect($this->documentObject['content']);
                }
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 2472
                  • 151 Posts
                  Quote from: sottwell at Aug 24, 2006, 11:48 PM

                  If you look at the code for dealing with a document of type "reference", you see that all it does is take the content of the doucment and immediately redirect the user to whatever URL the content is.
                  ...

                  Always eager to learn something new, where do you set the ’document type’ as you call it?

                  The only one coming close that I known off is the ’content type’ of the document, same thing?
                    A thing of beauty is a joy forever ( John Keats)
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    No, the mutate_content file does that automatically; if you mouse over the New Document and the New Weblink links in the menu, you’ll see that different values are passed in the query string. A weblink is automatically given the type "reference", while a document is given the type "document". This is not to be confused with the contentType, such as text/html, which you can choose from the select in the second tab.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 20339
                      • 11 Posts
                      If I understand correctly, as soon as MODx recognizes that the page is a Weblink, it does an immediate redirect without any further processing. So I guess the answer is No: we can’t use chunks, etc, in Weblink pages.

                      Perhaps there’s a workaround that involes using regular "content" pages, with the only content being a PHP snippet that does the redirect. Is that plausible? (Though I don’t have the first clue for how to go about it!)

                      Either way, sincere thanks for the help. I’m delighted at the responsiveness of the MODx community!

                      --Michael