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
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.
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.
-
☆ 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
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
-
☆ 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']);
}
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)
-
☆ 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.
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