-
Notifications
You must be signed in to change notification settings - Fork 0
/
analytics.html
134 lines (118 loc) · 4.99 KB
/
analytics.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="style.css" />
<title>ExactAlytics Dashboard</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Schibsted+Grotesk:ital,wght@0,400..900;1,400..900&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="text-align:center">
<h1>ExactAlytics Dashboard</h1>
<div style="padding:10px 0;"><div class="divider"></div></div>
<div id="alltop" class="flex">Loading Data...</div>
<div style="padding:10px 0;"><div class="divider"></div></div>
<div id="akad"></div>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js";
import { getDatabase, ref, set, get, child } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-database.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAwBo-LBbTZWimOAkgByg9zVd3sgwdON6U",
authDomain: "exactalytics.firebaseapp.com",
projectId: "exactalytics",
storageBucket: "exactalytics.appspot.com",
messagingSenderId: "2502194733",
appId: "1:2502194733:web:8b3ef42a216fa6bfbf2aa4"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getDatabase();
const dbRef = ref(db);
function decodeFB(text2) {
var text1 = text2.replaceAll("%2E",".").replaceAll("%23","#").replaceAll("%24","$").replaceAll("%2F","/").replaceAll("%5B","[").replaceAll("%5D","]").replaceAll('%22','"')
return text1;
}
get(child(dbRef, "/analytics/" + localStorage.getItem("apiKey"))).then((snapshot) => {
if (snapshot.exists()) {
var tosort = {}
var an = snapshot.val()
var atText = "";
Object.keys(an).forEach(function (k) {
if (k != "exists") {
if (an[k].embeds) {
var embText = an[k].embeds
} else {
var embText = "None"
}
atText = atText + "<div class='site'><h2 class='eTitle'>" + decodeFB(k) + "</h1>Site visits: " + an[k].clicks + "<br>Users: " + an[k].users + "<br>Page Embeds: " + embText + "<p><button onclick='getPageClicks(" + '"' + k + '"' + ",this)'>Views by Page</button></p></div>";
} else {
if (an[k] == true) {
atText = "No Data Yet"
}
}
});
alltop.innerHTML = atText
} else {alltop.innerHTML = "Error"};
});
function getPageClicks(id,btn) {
get(child(dbRef, "/analytics/" + localStorage.getItem("apiKey") + "/" + id + "/pages")).then((snapshot) => {
if (snapshot.exists()) {
var an = snapshot.val()
var atText = "";
Object.keys(an).forEach(function (k) {
atText = atText + "<br>" + decodeFB(k) + ": " + an[k] + " visits";
});
btn.parentElement.innerHTML = atText
} else {btn.parentElement.innerHTML = "No Analytics Data"};
});
}
window.getPageClicks = getPageClicks;
function setKey() {
get(child(dbRef, "/analytics/" + keyval.value)).then((snapshot) => {
if (snapshot.exists()) {
localStorage.setItem("apiKey",keyval.value)
location.reload()
} else {
alert("API key " + keyval.value + " does not exist.")
}
})
}
function cnKey(val) {
set(ref(db, "/analytics/" + val),{"exists":true})
}
function makeKey() {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let counter = 0;
while (counter < 13) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
get(child(dbRef, "/analytics/" + keyval.value)).then((snapshot) => {
if (snapshot.exists()) {
makeKey()
} else {
keyval.value = result;
cnKey(result)
}
})
}
window.setKey = setKey
window.makeKey = makeKey
</script>
<script>
if (!localStorage.getItem("apiKey")) {
document.title = "ExactAlytics"
document.body.innerHTML = "<h1>Get Started</h1><p>Enter an API key</p><input id='keyval' placeholder='Your API key'> <button onclick='setKey()'>Go to Dashboard</button><p><button onclick='makeKey()'>Generate a New One</button></p>"
} else {
akad.innerHTML = "<h3>Get ExactAlytics on your website</h3><textarea onclick='this.select()' readonly><script src='https://exactalytics.pages.dev/import.js'></script>\n<script>analyticsInit('[ENTER PROJECT NAME HERE]','" + localStorage.getItem("apiKey") + "')</script></textarea><div style='padding: 10px 0px;'><div class='divider'></div></div><h3>Your API key: " + localStorage.getItem("apiKey") + "</h3>";
}
</script>
</body>
</html>