Proxy guides
Nginx
Serve the ProductLense script from your own domain with an Nginx location block, and why events must not go through a plain proxy_pass.
Nginx can serve the script from your domain with a few lines. It should not forward events with proxy_pass: ProductLense would see your server's IP address for every visitor. To forward events, use a small route in your application server instead, as shown in the proxy overview.
Serve the script
server {
listen 443 ssl;
server_name example.com;
# ... your existing configuration
location = /js/a.js {
proxy_pass https://api.productlense.app/a.js;
proxy_set_header Host api.productlense.app;
proxy_ssl_server_name on;
proxy_ssl_name api.productlense.app;
proxy_hide_header Set-Cookie;
}
}proxy_ssl_server_name on sends the right hostname during the TLS handshake; without it the request to ProductLense fails. ProductLense's Cache-Control header passes through, so browsers cache the script for a day.
Then load the script from your path, with events going straight to ProductLense:
<script defer data-site="SITE_ID" data-api="https://api.productlense.app" src="/js/a.js"></script>Forward events
If you are on the Scale plan and want events to be first-party too, send /m/api/e to your application and let it add the visitor's IP address, as in the Express and Go examples:
location = /m/api/e {
proxy_pass http://127.0.0.1:3000; # your application, not ProductLense
proxy_set_header X-Forwarded-For $remote_addr;
client_max_body_size 8k;
}Check it works
- Run
nginx -t && nginx -s reload, then openhttps://example.com/js/a.js: it returns JavaScript. - Load a page with the developer tools open. The Network tab shows a
POSTtoapi/ewith status204. - Open the Live page in the ProductLense dashboard. Your visit appears within a few seconds.