Support server-side generated analytics data via POST from middleware #234
Replies: 10 comments 24 replies
-
@dch Although, not explicitly documented, you can find the event data documented here https://github.com/plausible/analytics/blob/master/lib/plausible_web/controllers/api/external_controller.ex#L73 To be clear, this is the data posted to the event controller in plain text. POST /api/event HTTP/1.1 {
"name": "pageview",
"url": "https://domain-added-to-plausible.com/your-page",
"domain": "domain-added-to-plausible.com",
"referrer": "https://tldr.net",
"source": "google",
"user_agent": "Mozilla",
"screen_width": 1920
} Most Appservers/Webservers dump the above information. NB: You need to pass-along the clients/visitors IP along with your call. use It being a plain rest call, you can write your own middle ware for your favorite framework for posting the data. Currently, there's no API key that is being passed along from the client side either. Technically, there's also some need of rate-limiting and/or filtering of bad-actors that might be addressed at a later point. |
Beta Was this translation helpful? Give feedback.
-
Same as #130, I will close that one in favour of this issue since the discussion seems to be here. Generally this would work and I have planned to support something like this in the future. Two issues come to mind:
|
Beta Was this translation helpful? Give feedback.
-
Regarding the bot detection, I have previously worked with yauaa and is pretty great at detecting bots or getting any sense of client based on UA analysis, if you can test it here. I would like to implement this in elixir or probably for Plausible but more on that later. |
Beta Was this translation helpful? Give feedback.
-
wow just seen that plausible is written in Elixir :-) 🚀 🔥 🍾 |
Beta Was this translation helpful? Give feedback.
-
I am (potentially) interested in this feature too. I'd like to add that a REST endpoint for adding data would ideally allow for batching too, so the back-end could have a buffer internally and then submit the requests to Plausible at regular intervals. This would allow for much better performance. From the standpoint of a REST API, it could be as simple as allowing an array of objects in addition to a single object, also providing the timestamp of the request. |
Beta Was this translation helpful? Give feedback.
-
I'm interested in this too, but for use from the browser, as a matter of avoiding remote-loaded JS. I could download the JS snippet and have my build process warn me when that changes, but that seems a bit brittle. |
Beta Was this translation helpful? Give feedback.
-
Hi. I also needed the same feature, and after searching for a while, i came across with this issue as well. I ended up reading through source code that @tckb pointed to, and also this file, and i quickly wrote this to send analytics server-side. It's a bit raw, but maybe you can adapt to what you need |
Beta Was this translation helpful? Give feedback.
-
I am also interested in this feature and I am willing to create a middleware for Go.
|
Beta Was this translation helpful? Give feedback.
-
You can take a look at our events API now https://plausible.io/docs/events-api |
Beta Was this translation helpful? Give feedback.
-
@metmarkosaric |
Beta Was this translation helpful? Give feedback.
-
Precheck
Prerequisites
Feature request
site visitors who disable javascript, or use adblocker tech, have their visits lost. CNAMEing and
similar tricks are already tracked and disabled by current adblockers, and this is likely to grow.
If we can send analytics data from the server side directly after each request, we get similar
data without needing any client-side tracking.
How would you like it to work
If the
POST /api/event
format is documented, it should be possible to submit the analytics dataserver side directly in the web framework, as pluggable middleware. This is both nice from a
configuration point of view, and also from an analytics view - we won't miss anything, and users
don't need to run the javascripts.
For example, in Elixir there are 2 major frameworks - Plug and Phoenix - which allow stackable
middleware. The analytics request can extract most of the info from haproxy or nginx details,
and the web server framework, so while we get a reduced set of info, we do get 90% of the value.
Ideally the
POST ...
request would only include the analytics data in the BODY, and use eitherHTTP Headers or a query parameter to track an API key, so that these can safely be logged
locally without exposing plausible.io API tokens.
Update: This is now live. You can take a look at our events API https://plausible.io/docs/events-api
Beta Was this translation helpful? Give feedback.
All reactions