Skip to content

Commit d890bed

Browse files
committed
Update Nginx guide
1 parent 688c75b commit d890bed

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

docs/proxy/guides/nginx.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@ If you're already running Nginx as your main web server or reverse proxy, you ca
88
Our managed proxy lets you send analytics through your own domain name as a first-party connection. All you need to do is set up a CNAME record using the instructions we'll send you and update the snippet on your site. We'll take care of everything else. [Contact us for details](https://plausible.io/contact).
99
:::
1010

11-
## Step 1: Update your Nginx config
11+
## Step 1: Get your snippet
12+
13+
In the "**Site Installation**" area of the "**General**" section in your [site settings](website-settings.md) you can see
14+
the snippet specific for your site. It will look similar to the following:
15+
16+
```html
17+
<script async src="https://plausible.io/js/pa-XXXXX.js"></script>
18+
<script>
19+
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
20+
plausible.init()
21+
</script>
22+
```
23+
24+
Your snippet will have a different script location than the example above. Look for the `https://plausible.io/js/pa-XXXXX.js` part in your snippet - that's the personalized location for your site's script. Mark it down for subsequent steps.
25+
26+
## Step 2: Update your Nginx config
1227

1328
```
1429
# Only needed if you cache the plausible script. Speeds things up.
@@ -24,7 +39,7 @@ proxy_cache_path /var/run/nginx-cache/jscache levels=1:2 keys_zone=jscache:100m
2439
server {
2540
2641
resolver 9.9.9.9; # Use quad9 DNS resolver. Remove this line if you've already configured a DNS resolver.
27-
set $plausible_script_url https://plausible.io/js/script.js; # Change this if you use a different variant of the script
42+
set $plausible_script_url https://plausible.io/js/pa-XXXXX.js; # Change this to path from step 1
2843
set $plausible_event_url https://plausible.io/api/event;
2944
...
3045
location = /js/script.js {
@@ -57,10 +72,16 @@ server {
5772
}
5873
```
5974

60-
## Step 2: Adjust your deployed script
75+
## Step 3: Adjust your deployed script
6176

6277
With the above config in place, you can change the script tag on your site as follows:
6378

6479
```html
65-
<script defer data-api="/api/event" data-domain="website.com" src="/js/script.js"></script>
80+
<script async src="/js/script.js"></script>
81+
<script>
82+
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
83+
plausible.init({
84+
endpoint: "/api/event"
85+
})
86+
</script>
6687
```

0 commit comments

Comments
 (0)