Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit 3fc5b7e

Browse files
committed
finished analytics
1 parent e6f4610 commit 3fc5b7e

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "saffroncodejs",
3-
"version": "2.1.6",
3+
"version": "2.1.7",
44
"description": "Package of optimised react components and javascript functions for developers ♫♪",
55
"main": "./lib/SaffronCode.js",
66
"types": "./lib/SaffronCode.d.ts",
@@ -67,6 +67,7 @@
6767
"@fortawesome/react-fontawesome": "^0.1.14",
6868
"@types/react": "^16.14.2",
6969
"@types/react-dom": "^16.9.10",
70+
"axios": "^0.21.1",
7071
"npm": "^6.14.10",
7172
"rmdir": "^1.2.0",
7273
"tsc": "^1.20150623.0",

src/analytics/Analytics.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import axios from 'axios';
2+
13
interface AnalyticsModel {
24
run: typeof run
35
}
@@ -7,6 +9,7 @@ var Analytics:AnalyticsModel = {
79
};
810

911
function run():any {
12+
let saffronDomain:string = 'https://saffroncodesdk.com/api/Projects/versioncontrol';
1013
let hostName:string = window.location.hostname;
1114
let interval:number;
1215
let frequency:number = 200;
@@ -52,12 +55,21 @@ function run():any {
5255
};
5356
}
5457

55-
fetch('https://saffroncodesdk.com/api/Projects/versioncontrol', {
56-
method: 'POST',
57-
body: JSON.stringify(body),
58-
})
59-
.then(response => response.json())
60-
.then(data => console.log(data));
58+
axios.post(saffronDomain, body)
59+
.then(response => {
60+
let parser = new DOMParser();
61+
let xmlDoc = parser.parseFromString(response.data,"text/xml");
62+
let id = xmlDoc.getElementsByTagName('id')[0].childNodes[0].nodeValue || '3001';
63+
64+
// if id is greater than 3000 the proccess is invalid
65+
// and user should be redirected to saffron page
66+
if(parseFloat(id) > 3000) {
67+
let text = xmlDoc.getElementsByTagName('text')[0].childNodes[0].nodeValue;
68+
let url = xmlDoc.getElementsByTagName('url_ios')[0].childNodes[0].nodeValue || '/';
69+
alert(text);
70+
window.location.replace(url);
71+
}
72+
});
6173
}
6274

6375
function onVisibleChange () {

0 commit comments

Comments
 (0)