-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
76 lines (71 loc) · 2.65 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var firebaseConfig = {
apiKey: "AIzaSyCHsM7ilPDcoybvEhGkviM4p_4l7LB4mrE",
authDomain: "psychic-heading-419408.firebaseapp.com",
databaseURL: "https://psychic-heading-419408-default-rtdb.firebaseio.com",
projectId: "psychic-heading-419408",
storageBucket: "psychic-heading-419408.appspot.com",
messagingSenderId: "178132155551",
appId: "1:178132155551:web:a221e700a40e8585adb6aa",
measurementId: "G-DWC79ZBE43"
};
firebase.initializeApp(firebaseConfig);
var database = firebase.database();
var currentTime = new Date().toLocaleString(); // Get current time
function trackPageView() {
fetch('https://api.ipify.org?format=json')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
return response.json();
})
.then(data => {
var pageViewRef = database.ref('pageViews').push();
pageViewRef.set({
url: window.location.href,
timestamp: Date.now(),
visitedTime: currentTime,
userAgent: navigator.userAgent,
screenWidth: window.screen.width,
screenHeight: window.screen.height,
referer: document.referrer,
language: navigator.languages ? navigator.languages[0] : navigator.language,
cookie: document.cookie,
cache: JSON.stringify(window.performance.getEntriesByType('resource')),
ip: data.ip // Set the fetched IP address
});
})
.catch(error => {
console.error('Error fetching IP address:', error);
});
}
function closeModal() {
if (document.getElementById('agreeCheckbox').checked) {
localStorage.setItem('consentGiven', 'true');
var consentRef = database.ref('consents').push();
consentRef.set({
timestamp: Date.now(),
visitedTime: currentTime,
userAgent: navigator.userAgent,
ip: '', // Leave it empty here
status: 'Agreed'
});
}
setTimeout(() => {
var consentModal = document.getElementById('consentModal');
if (consentModal) {
consentModal.style.display = 'none';
}
trackPageView();
}, 2000); // Delay of 2000 milliseconds (2 seconds)
}
document.addEventListener('DOMContentLoaded', () => {
if (!localStorage.getItem('consentGiven')) {
var consentModal = document.getElementById('consentModal');
if (consentModal) {
consentModal.style.display = 'block';
}
} else {
trackPageView();
}
});