You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-11Lines changed: 10 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,17 +10,20 @@ A tiny analytics server with less than 100 lines of code, easy to run and hack a
10
10
11
11
## Setup
12
12
13
-
1.`git clone [email protected]:mxstbr/micro-analytics` to get the repo.
14
-
2.`npm install` to install the dependencies.
15
-
3.`npm start` to start the service.
13
+
```
14
+
npm install -g micro-analytics-cli
15
+
micro-analytics
16
+
```
17
+
18
+
And that's it! 🎉 The analytics server is now running at `localhost:3000`. (see [`server-setup.md`](./server-setup.md) for instructions on acquiring a server and setting up `nginx` to make this publicly available)
16
19
17
-
And that's it! 🎉 (see [`deployment.md`](./deployment.md) for deployment instructions)
20
+
> **Note**: You can pass any option to the `micro-analytics` command that you can pass to [`micro`](https://github.com/zeit/micro). As an example, to change the host you'd do `micro-analytics -H 127.0.0.1`
18
21
19
22
## Usage
20
23
21
24
### Tracking views
22
25
23
-
To track a view, simply send a request to `/<yourpath>`. If you send a `GET` request, the request will increment the views and return the total views. If you send a `POST` request, the views will increment but you don't get the total views back.
26
+
To track a view, simply send a request to `/<id>`. If you send a `GET` request, the request will increment the views and return the total views for that id. If you send a `POST` request, the views will increment but you don't get the total views back.
24
27
25
28
This is how you'd track pageviews for a website: (though note that this can be used to track anything you want)
26
29
@@ -34,13 +37,9 @@ This is how you'd track pageviews for a website: (though note that this can be u
34
37
</script>
35
38
```
36
39
37
-
If you just want to get the views for a path and don't want to increment the views during a `GET` request, set `inc` to `false` in your query parameter. (`/<yourpath>?inc=false`)
38
-
39
-
If you want to get all views for all paths, set the `all` query parameter to `true`. (`/?all=true`)
40
-
41
-
## Contributing
40
+
If you just want to get the views for an id and don't want to increment the views during a `GET` request, set `inc` to `false` in your query parameter. (`/<id>?inc=false`)
42
41
43
-
If you run `npm run dev` the server will restart every time you edit the code. Perfect for development of `micro-analytics`!
42
+
If you want to get all views for all ids, set the `all` query parameter to `true`. (`/?all=true`)
Copy file name to clipboardExpand all lines: server-setup.md
+18-17Lines changed: 18 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,35 @@
1
-
# Deployment
1
+
# Server Setup
2
2
3
-
Deploying this service is a short three step process. This assumes you already have a server with an OS of your choice that runs Node setup, if not refer to the [acquire a server](#acquire-a-server) section.
3
+
Running `micro-analytics` on a server is a simple two step process:
4
4
5
-
1. Upload the files of the service to your server (you should be able to do this on your own)
6
-
2. Start and daemonize the app with `pm2`
7
-
3. Setup `nginx` as a reverse proxy to make your service publicy accessible
5
+
1. Start and daemonize the app with `pm2`
6
+
2. Setup `nginx` as a reverse proxy to make your service publicy accessible
7
+
8
+
## Prerequisite: A server
9
+
10
+
If you don't have a server to run this on yet, here is what I do:
11
+
12
+
I use and like [DigitalOcean](https://m.do.co/c/d371ed7f99af) (referral link) for my servers. A simple, 5$/month droplet will suffice to run this service reliably. (upgrading to more power in case of big traffic is two clicks away too)
13
+
14
+
Make sure to choose the `NodeJS x.x.x on 16.04` (where `x.x.x` is the highest version number you can find) one-click app when creating the droplet to get the server fully setup with Node and Ubuntu.
8
15
9
16
## Start and deamonize the app
10
17
11
-
Once all the files for this microservice are uploaded we'll use `pm2` to start and deamonize the app. This means that the app isn't bound to the terminal, and we'll also make `pm2` start the app when the server start.
18
+
Install `micro-analytics` on your server by running `npm install -g micro-analytics-cli` in its shell.
19
+
20
+
We'll use `pm2` to start and deamonize the app. This means that the app isn't bound to the terminal, and we'll also make `pm2` start the app when the server start. (this avoids the service being down in case your server reboots)
12
21
13
-
First run `npm install -g pm2` to get `pm2`, then run `pm2 start npm -- start`. This tells `pm2` to run `npm start` in the background.
22
+
First run `npm install -g pm2` to get `pm2`, then run `pm2 start micro-analytics`. This tells `pm2` to run `micro-analytics` in the background.
14
23
15
24
To make sure our service stays up even if the server reboots we run `pm2 startup ubuntu` (replace `ubuntu` with whatever OS you're using) and `pm2 save`.
16
25
17
26
## Set up `nginx`
18
27
19
-
Get `nginx` by running `sudo apt-get install nginx`, then configure it to reroute all incoming requests to the server to our server.
28
+
Get `nginx` by running `sudo apt-get install nginx`, then configure it to reroute all incoming requests to the server to `micro-analytics`.
20
29
21
30
Delete the default site from nginx by running `sudo rm /etc/nginx/sites-enabled/default`, then create a new one by running `sudo touch /etc/nginx/sites-enabled/<yoursite>`. (replace `<yoursite>` with your site name)
22
31
23
-
We want to reroute all requests for any path that come in to our service, so edit the `/etc/nginx/sites-enabled/<yoursite>` file to look like this:
32
+
We want to reroute all requests for any path that come in to `localhost:3000` (where `micro-analytics` is running), so edit the `/etc/nginx/sites-enabled/<yoursite>` file to look like this:
24
33
25
34
```nginx
26
35
server {
@@ -37,11 +46,3 @@ server {
37
46
```
38
47
39
48
(note that I have no idea what I'm doing here, this was copied from [this tutorial](https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-reverse-proxy-for-apache))
40
-
41
-
## Acquire a server
42
-
43
-
If you don't have a server to deploy this on just yet, here is what I do:
44
-
45
-
I use and like [DigitalOcean](https://m.do.co/c/d371ed7f99af) (referral link) for my servers. A simple, 5$/month droplet will suffice to run this service reliably. (upgrading to more power in case of big traffic is two clicks away too)
46
-
47
-
Make sure to choose the `NodeJS x.x.x on 16.04` (where `x.x.x` is the highest version number you can find) one-click app when creating the droplet to get the server fully setup with Node and Ubuntu.
0 commit comments