Our native integration allows data to be transferred automatically to a Google Sheet you have set up.
The advanced installation guide is for users who wish to:
Instructions to Implement Google Apps Script in Google Sheets
Open Your Google Sheet:
Go to Google Sheets and open the spreadsheet where you want to add the script.
Access the Script Editor:
Click on Extensions in the top menu.
Select Apps Script from the dropdown menu. This will open the Google Apps Script editor.
Delete Default Code:
If there’s any default code in the editor, select all and delete it.
Copy and Paste the Provided Code:
Copy the entire Google Apps Script code provided in the guide.
Paste it into the script editor. Ensure the comments within the code are included, as they provide important context and instructions.
Customize the Code (Optional):
Email Notifications:
If you want to send notifications to multiple emails, uncomment the line //sendLeadNotificationEmail(headers, rowData); by removing the //.
Set Notification Emails:
In the sendLeadNotificationEmail function, modify the recipients variable with your desired email addresses.
Set Sender Name and Reply-To Address:
Customize the name and replyTo fields in the options object.
Save the Script:
Click the disk icon or go to File > Save to save your script.
Authorize and Run the Script:
Click the Run button (play icon). You may be prompted to authorize the script to access your Google account data.
Follow the prompts to grant the necessary permissions.
Testing:
Test the script by triggering the function (e.g., via a form submission or manually) to ensure it writes data to your spreadsheet and sends notifications if configured.
Key Comments in the Code:
Email Notifications: Customize the recipients and options for sending email notifications.
Headers and Data Rows: The script sets headers and appends data rows to the spreadsheet.
That’s it! Your Google Apps Script is now set up and ready to use with your Google Sheet. For a visual guide, refer to the accompanying video.
function doPost(e) {
var spreadsheetId = e.parameter.spreadsheetId;
var sheet = SpreadsheetApp.openById(spreadsheetId).getActiveSheet();
var params = JSON.parse(e.postData.contents);
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
if (sheet.getLastRow() === 0) {
headers = Object.keys(params);
sheet.appendRow(headers);
}
var rowData = new Array(headers.length).fill("");
for (var key in params) {
if (params.hasOwnProperty(key)) {
var index = headers.indexOf(key);
if (index !== -1) {
rowData[index] = params[key];
}
}
}
sheet.appendRow(rowData);
return ContentService.createTextOutput("Data saved");
}
function sendLeadNotificationEmail(headers, rowData) {
var recipients = "email_1, email_2, email_3";
var options = {
name: "Your Custom Name",
replyTo: "replyto@example.com",
cc: "ccrecipient@example.com",
bcc: "bccrecipient@example.com"
};
var subject = "Lead Notification: New Lead from Your Website Chatbot";
var intro = "Hi! You have a new lead from your website bot! Here are the details:\n\n";
var leadDetails = "Lead Details:\n\n";
var signOff = "Thanks,\nNotification Bot";
for (var i = 0; i < headers.length; i++) {
if (rowData[i] !== "") {
leadDetails += headers[i] + ":\n" + rowData[i] + "\n\n";
}
}
var body = intro + leadDetails + signOff;
MailApp.sendEmail(recipients, subject, body, options);
}