2021-05-17 16:08:35 +00:00
|
|
|
export const stripTrailingSlash = ({ URL }) => {
|
|
|
|
return URL.replace(/\/$/, '');
|
|
|
|
};
|
|
|
|
|
|
|
|
// Format all campaigns
|
2021-05-18 06:45:23 +00:00
|
|
|
export const formatCampaigns = ({ campaigns }) => {
|
|
|
|
return campaigns.map(item => {
|
2021-05-17 16:08:35 +00:00
|
|
|
return {
|
|
|
|
id: item.id,
|
|
|
|
timeOnPage: item?.trigger_rules?.time_on_page,
|
|
|
|
url: item?.trigger_rules?.url,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Find all campaigns that matches the current URL
|
2021-05-18 06:45:23 +00:00
|
|
|
export const filterCampaigns = ({ campaigns, currentURL }) => {
|
|
|
|
return campaigns.filter(
|
2021-05-17 16:08:35 +00:00
|
|
|
item =>
|
|
|
|
stripTrailingSlash({ URL: item.url }) ===
|
|
|
|
stripTrailingSlash({ URL: currentURL })
|
|
|
|
);
|
|
|
|
};
|