Refactor mailpoet.com url factory
[MAILPOET-2182]
This commit is contained in:
committed by
M. Shull
parent
78d863b536
commit
fee4bbcd7b
@@ -1,10 +1,10 @@
|
||||
import FeaturesController from 'features_controller';
|
||||
import MailPoetUrlFactory from 'mailpoet_url_factory';
|
||||
import MailPoetComUrlFactory from 'mailpoet_com_url_factory';
|
||||
|
||||
// A placeholder for MailPoet object
|
||||
var MailPoet = {
|
||||
FeaturesController: FeaturesController(window.mailpoet_feature_flags),
|
||||
MailPoetUrlFactory: MailPoetUrlFactory(window.mailpoet_referral_id),
|
||||
MailPoetComUrlFactory: MailPoetComUrlFactory(window.mailpoet_referral_id),
|
||||
};
|
||||
|
||||
// Expose MailPoet globally
|
||||
|
27
assets/js/src/mailpoet_com_url_factory.js
Normal file
27
assets/js/src/mailpoet_com_url_factory.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const MailPoetComUrlFactory = referralId => {
|
||||
const baseUrl = 'https://www.mailpoet.com/';
|
||||
|
||||
const getUrl = (path, params) => {
|
||||
let finalParams = params;
|
||||
if (referralId) {
|
||||
finalParams.ref = referralId;
|
||||
}
|
||||
const url = new URL(path, baseUrl);
|
||||
Object.keys(finalParams).map(key => (url.searchParams.set(key, finalParams[key])));
|
||||
return url.toString();
|
||||
};
|
||||
|
||||
return {
|
||||
getFreePlanUrl: (params) => {
|
||||
const paramsObject = typeof params === 'object' ? params : {};
|
||||
paramsObject.utm_source = 'plugin';
|
||||
return getUrl('free-plan', paramsObject);
|
||||
},
|
||||
|
||||
getPricingPageUrl: subscribers => (
|
||||
getUrl('pricing', { subscribers })
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
export default MailPoetComUrlFactory;
|
@@ -1,27 +0,0 @@
|
||||
const addReferralId = (url, referralId) => {
|
||||
if (!referralId) {
|
||||
return url;
|
||||
}
|
||||
const refUrl = new URL(url);
|
||||
refUrl.searchParams.set('ref', referralId);
|
||||
return refUrl.toString();
|
||||
};
|
||||
|
||||
const MailPoetUrlFactory = referralId => ({
|
||||
getFreePlanUrl: (utmCampaign = null, utmMedium = null) => {
|
||||
const url = new URL(addReferralId('https://www.mailpoet.com/free-plan/?utm_source=plugin', referralId));
|
||||
if (utmCampaign) {
|
||||
url.searchParams.set('utm_campaign', utmCampaign);
|
||||
}
|
||||
if (utmMedium) {
|
||||
url.searchParams.set('utm_medium', utmMedium);
|
||||
}
|
||||
return url.toString();
|
||||
},
|
||||
|
||||
getPricingPageUrl: subscribersCount => (
|
||||
addReferralId(`https://www.mailpoet.com/pricing/?subscribers=${subscribersCount}`, referralId)
|
||||
),
|
||||
});
|
||||
|
||||
export default MailPoetUrlFactory;
|
Reference in New Issue
Block a user