@imrankhanjoya/visit-analytics 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -0
- package/src/index.js +2 -0
- package/src/models/Visit.js +38 -0
- package/src/trackVisit.js +28 -0
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@imrankhanjoya/visit-analytics",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"type": "commonjs"
|
|
13
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
const VisitSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
token: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true,
|
|
8
|
+
unique: true,
|
|
9
|
+
},
|
|
10
|
+
userinfo: {
|
|
11
|
+
type: [],
|
|
12
|
+
required: false,
|
|
13
|
+
default: []
|
|
14
|
+
},
|
|
15
|
+
path: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: true,
|
|
18
|
+
},
|
|
19
|
+
type: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: true,
|
|
22
|
+
},
|
|
23
|
+
ip: {
|
|
24
|
+
type: String,
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
date: {
|
|
28
|
+
type: String,
|
|
29
|
+
required: true,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
},
|
|
33
|
+
{ timestamps: true }
|
|
34
|
+
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export default mongoose.models.Visit ||
|
|
38
|
+
mongoose.model("Visit", VisitSchema);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const Visit = require("./models/Visit");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const saveVisit = async (visitData) => {
|
|
5
|
+
try {
|
|
6
|
+
const data = {token:token,ip:headersList,path:path,type:type,date:date,userinfo:[{username:username,image:image}]};
|
|
7
|
+
|
|
8
|
+
console.log("Visit saved successfully");
|
|
9
|
+
try{
|
|
10
|
+
const val = await Visits.create(data)
|
|
11
|
+
return val
|
|
12
|
+
}catch(e){
|
|
13
|
+
return e
|
|
14
|
+
}
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error("Error saving visit:", error);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const getVisits = async (path) => {
|
|
21
|
+
try {
|
|
22
|
+
const visits = await Visit.find({ path }).sort({ date: -1 });
|
|
23
|
+
return visits;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error("Error retrieving visits:", error);
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
}
|