fbpx

Integrasi Google Form ke Mailketing


Script GS :

function setupTriggers() {

  var form = FormApp.getActiveForm();
  ScriptApp.newTrigger("mailketing").forForm(form).onFormSubmit().create();

}
function mailketing(e) {

  try {

    var i = 0,
      lead = {},
      items = e.response.getItemResponses();

      lead.api_token='masukkan api token anda';
      lead.list_id='masukkan list_id';

    for (i = 0; i < items.length; i++) {

      var title = items[i].getItem().getTitle();
      var answer = items[i].getResponse().toString();

      switch (title) {
        case "Email":
          lead.email = answer;
          break;
        case "Nama":
          lead.first_name = answer;
          break;
        case "No Whatsapp":
          lead.mobile = answer;
          break;
      }
    }

    var response = UrlFetchApp.fetch(
      "https://be.mailketing.co.id/api/v1/addsubtolist", {
        method: "POST",
        payload: lead
      }
    );

    Logger.log(response.getContentText());

  } catch (error) {

    Logger.log(error.toString());

  }

}

Leave a Reply

Your email address will not be published. Required fields are marked *