Skip to content

Commit 43f04ac

Browse files
committed
feat: sync doc with bayanplus-js
1 parent 75902a7 commit 43f04ac

File tree

9 files changed

+152
-140
lines changed

9 files changed

+152
-140
lines changed

docs/getting-started/add-bayanplus-to-your-website.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,41 @@ title: Add Bayanplus to your website
33
sidebar_position: 1
44
---
55

6-
76
To add Bayanplus to your website, you will need to add the below this line of code to the `<head></head>` tag in you HTML file
87

9-
The tracking script has `pid` parameter which has your project id and you must add it so the script can work. You can find it in the setting page of your project, it will look something like this, or can copy and paste the code from the setting page in your project directly
8+
The tracking script has `data-pid` parameter which has your project id and you must add it so the script can work. You can find it in the setting page of your project, it will look something like this, or can copy and paste the code from the setting page in your project directly
109

1110
If you are using Javascript library/framework like React **we recommond checking** [this](../libraries/javascript.md)
11+
1212
```html
13-
<script defer pid="Your Project Id" src="https://cdn.bayanplus.co/bp.js"></script>
13+
<script
14+
defer
15+
data-pid="Your Project Id"
16+
src="https://cdn.bayanplus.co/bp.js"
17+
></script>
1418
```
15-
16-
:::info
19+
20+
:::info
1721

1822
Bayanplus will only accept tracking request that has project id parameter `pid` and are coming from the project exact domain and it is subdomains
1923

2024
:::
2125

22-
## Tracking from localhost
23-
Bayanplus does not accept data coming from developemt enviroment, so if you are in development mode using something like `localhost:3000` it wouldn't work. However, you can bypass that by passing `data-track-localhost`
26+
## Development mode
27+
28+
If you are in development mode using something like `localhost:3000` you can use the attribute `data-dev` which will not record events
29+
2430
```html
25-
<script defer data-track-localhost pid="Your Project Id" src="https://cdn.bayanplus.co/bp.js"></script>
31+
<script
32+
defer
33+
data-dev
34+
data-pid="Your Project Id"
35+
src="https://cdn.bayanplus.co/bp.js"
36+
></script>
2637
```
2738

2839
## Automatic tracking
2940

30-
All page views are **automatically tracked**, you don't need any extra configuration whatsoever, we send a new request anytime the URL changes. We track traditional websites that has many HTML pages and SPAs like React, Angular and Vue.
41+
All page views are **automatically tracked**, you don't need any extra configuration whatsoever, we send a new request anytime the URL changes. We track traditional websites that has many HTML pages and SPAs like React, Angular and Vue.
3142

3243
If you need custom event tracking like tracking button click or signup then definitely check out [custom event tracking](../how-to/track-custom-events.md)
Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Exclude pages from being tracked
3-
sidebar_position: 3
3+
sidebar_position: 4
44
---
55

66
By default Bayanplus does what is called [Automatic Tracking](/getting-started/add-bayanplus-to-your-website#automatic-tracking). But what if there are some pages in your website that you don't want them to be tracked and included in your dashboard? you can do that with the help of our script, the script will recognize the pages you want to be excluded and will just simple ignore them from being tracked
@@ -10,53 +10,60 @@ Here's how you can do that with help of our script
1010
## Use `data-exclude` to exclude pages
1111

1212
Once you have added the embedded [Bayanplus script](/getting-started/add-bayanplus-to-your-website) all you need to is to `data-exclude` attribute to the script with the pages you want to exclude.
13-
For example let's say we want to exclude `/login` page from being tracked.
13+
For example let's say we want to exclude `/login` page from being tracked.
1414

1515
Here's how it will look like:
16+
1617
```html
17-
<script defer data-exclude="/login" pid="Your Project Id" src="https://cdn.bayanplus.co/bp.js"></script>
18+
<script
19+
defer
20+
data-exclude="/login"
21+
data-pid="Your Project Id"
22+
src="https://cdn.bayanplus.co/bp.js"
23+
></script>
1824
```
25+
1926
You can see the attribute `data-exclude="/login"` was added to the origin script which will help up to exclude `/login` page and now it **will not** be count int your Bayanplus dashboard
2027

2128
:::caution
2229
You want to exclude a pages, just make sure to include '/' in the beginning.
23-
Do this `data-exclude="/login"`
24-
and not this `data-exclude="login"`
30+
Do this `data-exclude="/login"`
31+
and not this `data-exclude="login"`
2532
:::
2633

2734
## Exclude multiple pages
2835

2936
You can also exclude as many pages as you just make sure they are **coma-seperated**.
30-
For example let's say we want to exclude `/login`, `/register` and `/hello` from being tracked.
37+
For example let's say we want to exclude `/login`, `/register` and `/hello` from being tracked.
3138

3239
Just add them together and seperate them with a coma:
3340

3441
```html
35-
<script defer data-exclude="/login, /register, /hello" pid="Your Project Id" src="https://cdn.bayanplus.co/bp.js"></script>
42+
<script
43+
defer
44+
data-exclude="/login, /register, /hello"
45+
data-pid="Your Project Id"
46+
src="https://cdn.bayanplus.co/bp.js"
47+
></script>
3648
```
3749

38-
## Advanced pages excluding
39-
50+
## Advanced pages excluding
51+
4052
Bayanplus script will recognize the below format for excluding pages
53+
4154
```
4255
data-exclude="/login, /admin/*, /blog-*, /*/admin, /*/stat/*"
4356
```
44-
Any page listed in this format will not be tracked. The asterisk `*` in simple words means **anything**.
45-
46-
Example
47-
- `/admin/*` is `/admin/<anything>`, will exclude any path that comes after `/admin/` like
48-
`/admin/profile` or `/admin/password`
49-
50-
- `/blog-*` is `/blog-<anything>`, anything comes in format of `/blog-*` like `/blog-1` or `/blog-2323` will be excluded.
51-
52-
- `*/admin/` is `<anything>/admin `, will exclude any path comes in format of `*/admin` like `/users/admin`
53-
54-
- `*/stat/*` is `<anything>/stat/<anything> `, will exclude any path comes in format of `*/stat/*` like `/dashboard/stat/main`
55-
56-
5757

58+
Any page listed in this format will not be tracked. The asterisk `*` in simple words means **anything**.
5859

60+
Example
5961

62+
- `/admin/*` is `/admin/<anything>`, will exclude any path that comes after `/admin/` like
63+
`/admin/profile` or `/admin/password`
6064

65+
- `/blog-*` is `/blog-<anything>`, anything comes in format of `/blog-*` like `/blog-1` or `/blog-2323` will be excluded.
6166

67+
- `*/admin/` is `<anything>/admin `, will exclude any path comes in format of `*/admin` like `/users/admin`
6268

69+
- `*/stat/*` is `<anything>/stat/<anything> `, will exclude any path comes in format of `*/stat/*` like `/dashboard/stat/main`

docs/how-to/track-custom-events.md

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ Events are useful and powerful features, allowing you to get a better insights a
88
Bayanplus automatically groups all the events you visitors has done and show it on the dashboard. You can see from the picture the the name for all event, in our case we have `downloads`, `sign up`. The count tell you how many this event or actions has been done by your visitors, and the conversion is the perecentage of completion out of all the visitors. So for example if you had 1000 visitors last 24 hours, and only 100 from those have sign up, then the conversion rate would be 10%
99

1010
## Sending an event
11-
You can start sending custom events with no extra configurations, all you need is to make sure the script is installed, [click if you haven't](/getting-started/add-bayanplus-to-your-website).
11+
12+
You can start sending custom events with no extra configurations, all you need is to make sure the script is installed, [click if you haven't](/getting-started/add-bayanplus-to-your-website).
1213

1314
You can start using two options:
1415

1516
### Using Javascript
1617

17-
The Bayanplus script you havve installed already exposes Bayanplus object globally. You can access it in `window.bayanplus` or just `bayanplus` is enough. If you are using a javascript framework or build tool we recommand using our offical npm library [bayanplus-js](track-custom-events.md)
18+
The Bayanplus script you have installed already exposes Bayanplus object globally. You can access it in `window.bayanplus` or just `bayanplus` is enough. If you are using a javascript framework or build tool we recommand using our offical npm library [bayanplus-js](https://www.npmjs.com/package/bayanplus-js)
19+
20+
To track an event, simple call `bayanplus()` function in your code. and pass the name of the event you want, Sign up for example
1821

19-
To track an event, simple call `bayanplus()` function in your code. and pass the name of the event you want, Sign up for example
2022
```javascript
21-
window.bayanplus("Sign up")
23+
window.bayanplus.event("Sign up");
2224
// or
23-
bayanplus("Sign up")
25+
bayanplus.event("Sign up");
2426
```
25-
For the above example, the `Sign up` event will be recorded to current visitor session. The `bayanplus` function takes an argument which is the name of the event, we recommand giving **short and straightforward** events name
2627

28+
For the above example, the `Sign up` event will be recorded to current visitor session. The `event` function takes an argument which is the name of the event, we recommand giving **short and straightforward** events name
2729

2830
### Using HTML attributes
2931

@@ -34,30 +36,20 @@ You need to specfiy the name of the event and whenever this element is clicked B
3436
```html
3537
<button data-bayanplus-event="Sign up">Sign up to our website!</button>
3638
```
39+
3740
#### HTML Forms
3841

3942
Also it is easy to track form submission just in same way using above example
40-
just append `data-bayanplus-event` to the form element.
43+
just append `data-bayanplus-event` to the form element.
4144
If the user submits the form the an event will be triggered, in below example it is called `Subscribe to newsletter`
4245

46+
:::info
47+
Bayanplus will not send or record any custom data like passwords our email in below case, only the event name, so do not worry about this
48+
:::
49+
4350
```html
4451
<form data-bayanplus-event="Subscribe to newsletter">
4552
<input name="email" type="email" />
4653
<button type="submit">Subscribe</button>
4754
</form>
4855
```
49-
:::info
50-
Bayanplus will not send or record any custom data like passwords our email in above case, only the event name, so do not worry about this
51-
:::
52-
53-
## Important note
54-
Please make sure you **do not include** any personally identifiable information (PII) in sending event to bayanplus. This might include `Phone number`, `Email`, `IP address`
55-
56-
For example, the below example is **highly discouraged and bad a example**
57-
```javascript
58-
// user ip address is considered personall data
59-
bayanplus(`IP ${getUserIPaddress()}`)
60-
61-
// some cookies are senstive
62-
bayanplus(`session ${getCookieByName("session_id")}`)
63-
```

docs/how-to/track-subdomains.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
---
22
title: Track subdomains
3-
sidebar_position: 2
3+
sidebar_position: 3
44
---
55

6-
7-
8-
It is common for a business also to have multiple subdomains along (eg. `docs.bayanplus.co`, `cdn.bayanplus.co`) so If your website has subdomains you want to track it also, you can do so with two options. Either create new project for this subdomain, or re-use the same script across the subdomains.
6+
It is common for a business also to have multiple subdomains along (eg. `docs.bayanplus.co`, `cdn.bayanplus.co`) so If your website has subdomains you want to track it also, you can do so with two options. Either create new project for this subdomain, or re-use the same script across the subdomains.
97

108
:::info
119
When Bayanplus recieves new tracking request, it checks the `host` and see if it matches the domain of project or it is subdomain, if so it accepts it otherwise distract it.
1210
:::
1311

14-
## Tracking subdomains options
12+
## Tracking subdomains options
13+
1514
In simple words, you can do either of these things:
15+
1616
- **Multiple subdomains, multiple dashboards**:
17-
For each subdomains you have (eg. `docs.bayanplus.co`, `cdn.bayanplus.co`) you can create a project for each one with isolated dashboard, each project (subdomain) will have it is own script.
18-
Sessions will be isolated for each subdomains (eg. if someone visited `cdn.bayanplus.co` and then went to `docs.bayanplus.co` it will be counted as one two seperate sessions)
19-
- **Multiple subdomains, one dashboard**,
20-
Create just one project that for your domains and all your subdomains you want track, and place the same script on all the subdomains. Sessions will be tracked across the subdomains (eg. if someone visited `cdn.bayanplus.co` and then went to `docs.bayanplus.co` it will be counted as one session).
17+
For each subdomains you have (eg. `docs.bayanplus.co`, `cdn.bayanplus.co`) you can create a project for each one with isolated dashboard, each project (subdomain) will have it is own script.
18+
Sessions will be isolated for each subdomains (eg. if someone visited `cdn.bayanplus.co` and then went to `docs.bayanplus.co` it will be counted as one two seperate sessions)
19+
- **Multiple subdomains, one dashboard**,
20+
Create just one project that for your domains and all your subdomains you want track, and place the same script on all the subdomains. Sessions will be tracked across the subdomains (eg. if someone visited `cdn.bayanplus.co` and then went to `docs.bayanplus.co` it will be counted as one session).
2121

22-
For example, If someone visited `bayanplus.co` after few minutes went to `docs.bayanplus.co` to read the documenation. Since both domains use the same script (the 2nd option). Bayanplus will automatically group and merge the tracking data made across those domains in one dashboard for you.
22+
For example, If someone visited `bayanplus.co` after few minutes went to `docs.bayanplus.co` to read the documenation. Since both domains use the same script (the 2nd option). Bayanplus will automatically group and merge the tracking data made across those domains in one dashboard for you.
2323

24-
**It is more convenient and easier to use the 2nd option** which you can simply just put the script on one or more domains (eg. `bayanplus.co`, `docs.bayanplus.co`) and Bayanplus will merge the analytics data then for you.
24+
**It is more convenient and easier to use the 2nd option** which you can simply just put the script on one or more domains (eg. `bayanplus.co`, `docs.bayanplus.co`) and Bayanplus will merge the analytics data then for you.

docs/how-to/track-users.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Track users
3+
sidebar_position: 2
4+
---
5+
6+
Creating user profiles allows you to store custom data about your users, such as their name, email, or ID, in addition to the data that Bayanplus already stores, you can view them in Users page. A profile is a user with attached custom data.
7+
8+
To create a basic profile, you can use the `bayanplus.user.set()` function and provide the desired data, like this:
9+
10+
```typescript
11+
bayanplus.user.set({
12+
id: 123456,
13+
name: "Salah",
14+
15+
});
16+
```
17+
18+
## Authenticate your users
19+
20+
If you want to authenticate your users, you can set a unique ID using the same function, this is useful
21+
if you have multiple apps or devices and you want track the user across them.
22+
Bayanplus will recognised **id** as unique identifier.
23+
It will convert anonymous session into a **Profile**
24+
25+
```typescript
26+
bayanplus.user.set({ id: 123456 });
27+
```
28+
29+
## Write custom data
30+
31+
When you create a user profile, you can attach custom data to the user, such as their plan type or their preferred color scheme. You can set this data using the `bayanplus.user.set()` function:
32+
33+
```typescript
34+
bayanplus.user.set({ plan: "free", isDarkMode: true });
35+
bayanplus.user.set({ name: "Salah", email: "[email protected]" });
36+
```
37+
38+
You can call this function at any time to store data for the user. By default, data is appended to any existing data for the user. If you provide a field that already exists, it will be overwritten.
39+
40+
To retrieve the data you have set for the user, you can use the `bayanplus.user.get()` function.

docs/intergrations/nextjs.md

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,25 @@ yarn add bayanplus-js
1212
```
1313

1414
## Usage
15+
1516
After you install it, you can start using it by calling `bayanplus.init()` and pass the `projectId` as a parameter to so bayanplus can recognize you project. After that **Bayanplus will track page views automatically** [see this](../getting-started/add-bayanplus-to-your-website.md#automatic-tracking)
16-
```javascript
17-
// /pages/_app.js
18-
import bayanplus from 'bayanplus-js'
19-
useEffect(() => {
20-
bayanplus.init({
21-
projectId: "xxxx",
22-
})
23-
}, [])
24-
return <Component {...pageProps} />
25-
```
26-
## Tracking with localhost
27-
Bayanplus does not accept data coming from developemt enviroment, so if you are in development mode using something like `localhost:3000` it wouldn't work. However, you can bypass that by passing `trackLocalhost: true`
2817

2918
```javascript
3019
// /pages/_app.js
31-
import bayanplus from 'bayanplus-js'
32-
function MyApp({ Component, pageProps }) {
33-
20+
import bayanplus from "bayanplus-js";
3421
useEffect(() => {
35-
bayanplus.init({
36-
projectId: "xxxx",
37-
trackLocalhost: true,
38-
})
39-
}, [])
40-
41-
return <Component {...pageProps} />
42-
}
43-
export default MyApp;
22+
bayanplus.init({
23+
projectId: "xxxx",
24+
isDev: false, // if you data set to `true` so your data won't be tracked in case you are in development mode
25+
});
26+
}, []);
27+
return <Component {...pageProps} />;
4428
```
4529

4630
## Sending custom events
31+
4732
```javascript
48-
import bayanplus from 'bayanplus-js'
33+
import bayanplus from "bayanplus-js";
4934
import { useState } from "react";
5035

5136
export function SignupForm(props) {
@@ -54,7 +39,7 @@ export function SignupForm(props) {
5439
const handleSubmit = (e) => {
5540
e.preventDefault();
5641
// Record custom event on submit
57-
bayanplus("Signup to newsletter");
42+
bayanplus.event("Signup to newsletter");
5843
};
5944

6045
return (
@@ -71,4 +56,4 @@ export function SignupForm(props) {
7156
</form>
7257
);
7358
}
74-
```
59+
```

docs/intergrations/reactjs.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ title: ReactJS
33
sidebar_position: 2
44
---
55

6-
7-
To integrate Bayanplus to your React application, **you have two options**, either embed the Bayanplus script in you html file [see here](../getting-started/add-bayanplus-to-your-website.md)
6+
To integrate Bayanplus to your React application, **you have two options**, either embed the Bayanplus script in you html file [see here](../getting-started/add-bayanplus-to-your-website.md)
87

98
Or to install the offical npm library by running
109

@@ -15,24 +14,21 @@ yarn add bayanplus-js
1514
```
1615

1716
## Usage
17+
1818
After you install it, you can start using it by calling `bayanplus.init()` and pass the `projectId` as a parameter to so bayanplus can recognize you project. After that **Bayanplus will track page views automatically** [see this](../getting-started/add-bayanplus-to-your-website.md#automatic-tracking)
19+
1920
```javascript
20-
import bayanplus from 'bayanplus-js'
21+
import bayanplus from "bayanplus-js";
2122

2223
// first and most important initiliaze the app with the project id
2324
// you can find the project id on https://bayanplus.co
2425
// you only need to do this once
2526
bayanplus.init({
26-
projectId: 'xxxxx'
27-
})
27+
projectId: "xxxxx",
28+
isDev: false,
29+
});
2830

29-
// if you are in development mode
30-
bayanplus.init({
31-
projectId: 'xxxxx',
32-
trackLocalhost:true
33-
})
3431
// now you can track any event you want like
3532
// you can track as many events you want on any file as long as you initiliazed the app
36-
bayanplus.track('Buy Book')
37-
38-
```
33+
bayanplus.event("Buy Book");
34+
```

0 commit comments

Comments
 (0)