Hi there,
I use release manager in order to test two versions of my site.
I call wix-fetch from the backend whenever a new user enters my site to send an HTTP request to a server I made which monitors my traffic.
When I look at the logs, I see that sometimes the fetch function is executed more than once, for some reason, with a difference of a second between them, approximately.
Any ideas why this is happening? I want to fetch only once, that is, with every new user.
This is how my code looks like:
Home (front):
import wixLocation from 'wix-location';
import wixData from "wix-data";
import {newView, formSubmitted} from 'backend/serviceModule';
// MAIN CODE FILE
$w.onReady(function() {
console.log("User entered the site, url: " + wixLocation.url);
newView();
$w("#getSubscribers").onWixFormSubmitted(function ({fields}) {
formSubmitted('main');
let position = fields[0].fieldValue;
let email = fields[1].fieldValue;
let referral = wixLocation.url;
console.log("Home has been submitted");
let item = {
'Position': position,
'Email': email,
'Referral': referral
}
wixData.insert("lightboxSubscribe053", item);
});
});
serviceModule.jsw (back):
import {fetch} from 'wix-fetch';
export function newView () {
return fetch("myserverapilink", {"method": "get"})
.then( (httpResponse) => {
if (httpResponse.ok) {
return "Fetch VIEW succeeded";
} else {
return Promise.reject("Fetch VIEW did not succeed");
}
} )
.then(message => console.log(message))
.catch(err => console.log(err));
}
export function formSubmitted (form) {
return fetch("myserverapilink" + form + "-form", {"method": "get"})
.then( (httpResponse) => {
if (httpResponse.ok) {
return "Fetch FORM submission succeeded. Form type: " + form;
} else {
return Promise.reject("Fetch FORM submission did not succeed. Form type: " + form);
}
} )
.then(message => console.log(message))
.catch(err => console.log(err));
}
Thank you in advance!