Skip to content

Instantly share code, notes, and snippets.

@theindianappguy
Created December 30, 2023 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theindianappguy/5de570b9a8360c9a2097ab87838f4dbc to your computer and use it in GitHub Desktop.
Save theindianappguy/5de570b9a8360c9a2097ab87838f4dbc to your computer and use it in GitHub Desktop.
GoogleSheets-MailerLite-Integration-Automated-Email-Script
function doPost(request) {
// Open Google Sheet using ID
var sheet = SpreadsheetApp.openById("SHEETID");
var result = { "status": "SUCCESS" };
// try {
// Get all Parameters
var email = request.parameter.email || "";
var source = request?.parameter.source ?? "";
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
var todayString = mm + '/' + dd + '/' + yyyy;
Logger.log(todayString)
// Append data on Google Sheet
var rowData = sheet.appendRow([email, source, todayString, today.toString()]);
// add user to the onboarding emails --------------------------------------------------
// Add to Maillerlite Group
var newCustomerMagicSlidesGroupID = "GROUP_ID";
var apiKeyMagicSlides = "API_KEY";
addEmailtoMailerlite({
email: email,
apiKey: apiKeyMagicSlides,
groupId: newCustomerMagicSlidesGroupID,
});
// ----------------- end --------------------------------------------------
// } catch (exc) {
// If error occurs, throw exception
// result = { "status": "FAILED", "message": exc };
// }
// Return result
return ContentService
.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON);
}
async function addEmailtoMailerlite({ email, apiKey, groupId }) {
Logger.log("email " + email + " apiKey " + apiKey + " groupId " + groupId)
// try {
var url =
"https://add-email-to-mailerlite.vercel.app/addmail" +
`?email=${email}` +
`&groupId=${groupId}` +
`&apiKey=${apiKey}`;
Logger.log(url + "url")
var response = await UrlFetchApp.fetch(url, { muteHttpExceptions: true });
Logger.log(response);
// } catch (error) {
// Logger.log(`Error in addEmailtoMailerlite: ${error}`);
// }
}
@theindianappguy
Copy link
Author

` const [visitorEmail, setvisitorEmail] = useState("");
const [pushingEmail, setpushingEmail] = useState(false);

function pushEmails(e: any) {
e.preventDefault()
setpushingEmail(true)
console.log(visitorEmail: ${visitorEmail});
// check if validated email if not return
if (!ValidateEmail(visitorEmail)) {
showSnackbar("Email not valid");
setpushingEmail(false)
return;
}
console.log(document.referrer: ${document.referrer});
var myHeaders = new Headers();
myHeaders.append(
"Cookie",
"S=maestro=3x22VQghgpKcECF_GKqtuRrqh5gSi9LKkBjykWc4WGw"
);

    var requestOptions: RequestInit = {
        method: "POST",
        headers: myHeaders,
        redirect: "follow",
    };

    if (visitorEmail) {
        // email@gmail.com APPSCRIPT_EDIT_URL/edit
        fetch(
            `EXEC_URL?email=${visitorEmail}&source=${document.referrer} `,
            requestOptions
        )
            .then(function (response) {
                response.text();
                // document.getElementById(`${buttonId}`).value = "Try Free Now →"; // change button text
                // window.open(
                //     "https://chrome.google.com/webstore/detail/webcopilotco/dpbbbjcogocehfjmeggcfncdmijbaimg",
                //     "_self"
                // );
       
                setpushingEmail(false)
                // router.push("/pricing")
                window.open(
                    "https://workspace.google.com/marketplace/app/certifysimple_app_certificate_maker/132312197152",
                    "_self"
                );
            })
            .then((result) => console.log(result))
            .catch(function (error) {
                console.log("error", error);
                setpushingEmail(false)
                // document.getElementById(`${buttonId}`).value = "Try Free Now →"; // change button text
            });
    }
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment