Very related and helpful: Send event to Google Analytics using API server sided
A download link is sent to a customer via email:
Hello,
Please find your product here: https://www.example.com/files/yourfile.zip
I'd like to track this download in Google Analytics, as a Goal conversion.
Unfortunately, when the user clicks on the link, the file is directly delivered by the web server, without going trough a .html page.
How to track such a direct file download inside Analytics?
Should I add a dummy HTML page "in the middle", that would use the
analytics.jstracking snippet and send a download event to GA withga.send(...), and then redirect to the actual file after 500 milliseconds withsetTimeout(redirect, 500)? Is it really a clean and safe solution? I see many little potential issues: is 500 ms ok? what kind of redirection should be used? Also a user with JS disabled will never get his file... or if using<noscript>no Goal conversion can be recorded.Is there a way to ask Apache (who serves the
yourfile.zipto the client) or PHP to send a tracking event to GoogleAnalytics when this file is served?Another solution?
It seems that solution 2. would have the advantage of being 100% reliable, no matter the client has JS enabled or not.
But on the other hand, I don't want to use a very-few used hack. What is the usual solution for this very common situation?