Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email newsletter sign up forms for sidebar ads #2159

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions static/js/NewsletterSignUpForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function NewsletterSignUpForm({
includeEducatorOption = true,
emailPlaceholder = {en: 'Sign up for Newsletter', he: "הרשמו לניוזלטר"},
subscribe=Sefaria.subscribeSefariaNewsletter, // function which sends form data to API to subscribe
additionalNewsletterMailingLists = [],
}) {
const [email, setEmail] = useState('');
const [firstName, setFirstName] = useState('');
Expand All @@ -24,15 +25,15 @@ export function NewsletterSignUpForm({
if (showNameInputs === true) { // submit
if (firstName.length > 0 && lastName.length > 0) {
setSubscribeMessage("Subscribing...");
subscribe(firstName, lastName, email, educatorCheck).then(res => {
subscribe(firstName, lastName, email, educatorCheck, additionalNewsletterMailingLists).then(res => {
setSubscribeMessage("Subscribed! Welcome to our list.");
Sefaria.track.event("Newsletter", "Subscribe from " + contextName, "");
}).catch(error => {
setSubscribeMessage(error?.message || "Sorry, there was an error.");
setShowNameInputs(false);
});
} else {
setSubscribeMessage("Please enter a valid first and last name");// get he copy
setSubscribeMessage("Please enter a valid first and last name");
}
} else if (Sefaria.util.isValidEmailAddress(email)) {
setShowNameInputs(true);
Expand Down
81 changes: 47 additions & 34 deletions static/js/Promotions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classNames from "classnames";
import Sefaria from "./sefaria/sefaria";
import {EnglishText, HebrewText, InterfaceText, OnInView} from "./Misc";
import $ from "./sefaria/sefariaJquery";
import { NewsletterSignUpForm } from "./NewsletterSignUpForm";

const Promotions = () => {
const [inAppAds, setInAppAds] = useState(Sefaria._inAppAds); // local cache
Expand Down Expand Up @@ -36,6 +37,11 @@ const Promotions = () => {
buttonIcon: sidebarAd.buttonIcon,
buttonLocation: sidebarAd.buttonAboveOrBelow,
hasBlueBackground: sidebarAd.hasBlueBackground,
isNewsletterSubscriptionInputForm: sidebarAd.isNewsletterSubscriptionInputForm,
newsletterMailingLists:
sidebarAd.newsletterMailingLists?.data.map(
(mailingLists) => mailingLists.attributes.newsletterName
) ?? [],
trigger: {
showTo: sidebarAd.showTo,
interfaceLang: "english",
Expand Down Expand Up @@ -209,40 +215,47 @@ const SidebarAd = React.memo(({ context, matchingAd }) => {
);
}

return (
<OnInView onVisible={() => trackSidebarAdImpression(matchingAd)}>
<div className={classes}>
<h3
className={context.interfaceLang === "hebrew" ? "int-he" : "int-en"}
>
{matchingAd.title}
</h3>
{matchingAd.buttonLocation === "below" ? (
<>
<p
className={
context.interfaceLang === "hebrew" ? "int-he" : "int-en"
}
>
{matchingAd.bodyText}
</p>
{getButton()}
</>
) : (
<>
{getButton()}
<p
className={
context.interfaceLang === "hebrew" ? "int-he" : "int-en"
}
>
{matchingAd.bodyText}
</p>
</>
)}
</div>
</OnInView>
);
const isHebrew = context.interfaceLang === "hebrew";
const getLanguageClass = () => (isHebrew ? "int-he" : "int-en");

return (
<OnInView onVisible={() => trackSidebarAdImpression(matchingAd)}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove the OnInView component to work with the new analytics module we have created

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do this in a future PR. Tracking the views of the sidebar ads will not be important for email sign-ups right now

<div className={classes}>
<h3 className={getLanguageClass()}>{matchingAd.title}</h3>
{matchingAd.buttonLocation === "below" ? (
matchingAd.isNewsletterSubscriptionInputForm ? (
<>
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
<NewsletterSignUpForm
context={"Sidebar Ad: " + context.keywordTargets.toString()}
includeEducatorOption={false}
additionalNewsletterMailingLists={matchingAd.newsletterMailingLists}
/>
</>
) : (
<>
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
{getButton()}
</>
)
) : matchingAd.isNewsletterSubscriptionInputForm ? (
<>
<NewsletterSignUpForm
context={"Sidebar Ad: " + context.keywordTargets.toString()}
includeEducatorOption={false}
additionalNewsletterMailingLists={matchingAd.newsletterMailingLists}
/>
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
</>
) : (
<>
{getButton()}
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
</>
)}
</div>
</OnInView>
);
});

export { Promotions, GDocAdvertBox };
8 changes: 8 additions & 0 deletions static/js/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ function StrapiDataProvider({ children }) {
showTo
startTime
updatedAt
isNewsletterSubscriptionInputForm
newsletterMailingLists {
data {
attributes {
newsletterName
}
}
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion static/js/sefaria/sefaria.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,13 @@ Sefaria = extend(Sefaria, {
Sefaria._portals[portalSlug] = response;
return response;
},
subscribeSefariaNewsletter: async function(firstName, lastName, email, educatorCheck) {
subscribeSefariaNewsletter: async function(firstName, lastName, email, educatorCheck, lists = []) {
const payload = {
language: Sefaria.interfaceLang === "hebrew" ? "he" : "en",
educator: educatorCheck,
firstName: firstName,
lastName: lastName,
...(lists?.length && { lists }),
};
return await Sefaria.apiRequestWithBody(`/api/subscribe/${email}`, null, payload);
},
Expand Down
1 change: 1 addition & 0 deletions static/js/sefaria/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ const Strings = {
"Please enter a valid email address.": 'כתובת הדוא"ל שהוזנה אינה תקינה.',
"Subscribed! Welcome to our list.": "הרשמה בוצעה בהצלחה!",
"Sorry, there was an error.": "סליחה, ארעה שגיאה",
"Please enter a valid first and last name.": "נא להוסיף שם פרטי ושם משפחה.",

// Footer
"Connect": "צרו קשר",
Expand Down
13 changes: 0 additions & 13 deletions static/js/sefaria/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,6 @@ class Util {
};
const postData = {json: JSON.stringify(feedback)};
$.post('/api/send_feedback', postData);
}
static subscribeToNbList(email, lists) {
if (Sefaria.util.isValidEmailAddress(email)) {
$.post("/api/subscribe/" + email + "?lists=" + lists, function(data) {
if ("error" in data) {
console.log(data.error);
} else {
console.log("Subscribed! Welcome to our list.");
}
}).error(data => console.log("Sorry, there was an error."));
} else {
console.log("not valid email address")
}
}
static naturalTimePlural(n, singular, plural) {
return n <= 1 ? singular : plural;
Expand Down
Loading