- A log token
- An encoded payload (see below)
- A web page or HTML email to embed it in
How to encode your log dataTo ensure what you’re logging doesn’t get mangled in a URL, you need to base64 encode it. In a browser, you can convert your data from the JS console as a one-liner. Taking the “Hello, Logentries!” string:
var encoded = encodeURIComponent(btoa("Hello, Logentries")); // => 'SGVsbG8sIExvZ2VudHJpZXM%3D'will give you a properly encoded & formatted payload. If you’re building the URLs on the server-side, chances are your language / framework can easily generate a payload. Here’s an example using Ruby:
require 'base64' encoded = Base64.urlsafe_encode64("Hello, Logentries!") # => 'SGVsbG8sIExvZ2VudHJpZXM%3D'
Using the APIYou can make a call by building a URL like this:
https://js.logentries.com/v1/logs/TOKEN?e=DATAwhere TOKEN is the log token and DATA is the base64 encoded string. DATA must be assigned to the ‘?e=’ query parameter (you’ll get a HTTP ‘bad request’ response if you leave it out). You change the URL to use unencrypted http as opposed to https, but we don’t recommend it unless you have to.
ExampleTo log the string “Hello, Logentries”, the URL would look something like:
https://js.logentries.com/v1/logs/13a65478-4fae-42bb-8ce0-a01dd11di50q?e=SGVsbG8sIExvZ2VudHJpZXM%3DYou’ll probably want to embed this url in an HTML <img/> tag like this*:
<html lang="en"> <head> <title>Pixel tracker example</title> </head> <body> <img src="https://js.logentries.com/v1/logs/13a65x78-4fae-42bb-8ce0-a01dd11di50q?e=SGVsbG8sIExvZ2VudHJpZXM%3D/> </body> </html>*we made up that token- you’ll have to change it for one of your own!