fix: prevent exit intent and scroll intent in js package to make api call (#1350)

This commit is contained in:
Shubham Palriwala
2023-10-20 17:57:45 +05:30
committed by GitHub
parent f70cda6e11
commit a7072580d3
+21 -17
View File
@@ -6,6 +6,8 @@ import { renderWidget } from "./widget";
const logger = Logger.getInstance();
const config = Config.getInstance();
const intentsToNotCreateOnApp = ["Exit Intent (Desktop)", "50% Scroll"];
export const trackAction = async (
name: string,
properties: TJsActionInput["properties"] = {}
@@ -17,25 +19,27 @@ export const trackAction = async (
properties: properties || {},
};
const res = await fetch(`${config.get().apiHost}/api/v1/js/actions`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
if (!intentsToNotCreateOnApp.includes(name)) {
const res = await fetch(`${config.get().apiHost}/api/v1/js/actions`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(input),
});
if (!res.ok) {
const error = await res.json();
return err({
code: "network_error",
message: `Error tracking event: ${JSON.stringify(error)}`,
status: res.status,
url: res.url,
responseMessage: error.message,
body: JSON.stringify(input),
});
if (!res.ok) {
const error = await res.json();
return err({
code: "network_error",
message: `Error tracking event: ${JSON.stringify(error)}`,
status: res.status,
url: res.url,
responseMessage: error.message,
});
}
}
logger.debug(`Formbricks: Event "${name}" tracked`);