Skip to content

feat: add Firestore database setup instructions and configuration #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions source/docs/third-party-services/statistics-and-analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,40 @@ Firebase Analytics provides the functionality of visitor statistics.
<!-- tab Get apiKey & projectId → -->
Login to [Firebase](https://console.firebase.google.com/u/0/) to get apiKey and projectId. The Web API Key gets generated once you go into the "Authentication" section for the first time.

![Firebase](/images/firebase-1.png)
![Firebase](/images/firebase.png)

[More detailed documentation](https://firebase.google.com/docs/firestore/)
<!-- endtab -->

<!-- tab Create Firestore Database → -->
1. Create a Firestore database in Firebase console.

![Firestore](/images/firestore-1.png)
![Firestore](/images/firestore-2.png)

2. Apply these rules in Firestore Database Rules:

```js
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /articles/{document=**} {
allow read, create: if true;
allow write: if request.resource.data.count==resource.data.count+1;
}
match /{document=**} {
allow read, write: if false;
}
}
}
```

This configuration allows anyone to read the visitor count but prevents unauthorized writes to the database.

![Firestore](/images/firestore-3.png)
<!-- endtab -->

<!-- tab NexT Config -->
Edit {% label primary@NexT config file %} and add or change `firestore` section:

Expand All @@ -199,6 +228,10 @@ firestore:
apiKey: #required
projectId: #required
```
Note: Firestore visitor counting tracks unique visitors (UV) only. The count won't increase on page refresh as it uses browser's localStorage. To test the counter:
- Clear localStorage in Developer Tools
- Use incognito/private mode
- Use different browsers
<!-- endtab -->
{% endtabs %}

Expand Down
Binary file added source/images/firebase-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/images/firestore-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/images/firestore-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/images/firestore-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading