Last active
January 5, 2024 02:15
-
-
Save saamerm/df7abdaed35404faab9c28edecdc4bfe to your computer and use it in GitHub Desktop.
App Script to get info from a tracker connected to this https://codepen.io/saamerm/pen/yLwYvXe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doGet(request){ | |
var result = processRequest(request); | |
return ContentService | |
.createTextOutput(result) | |
.setMimeType(ContentService.MimeType.TEXT); | |
} | |
function processRequest(e) | |
{ | |
// Open Google Sheet using ID | |
var sheet = SpreadsheetApp.openById("{REPLACE_ME}"); | |
var result = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; | |
try{ | |
// Get all Parameters | |
var today = new Date(); | |
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate(); | |
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); | |
var dateTime = date+' '+time; | |
var info = "No extra info" | |
if (e && e.queryString && e.queryString.length > 0 ){ | |
info = e.queryString | |
} | |
// Append data on Google Sheet | |
var rowData = sheet.appendRow(["Email", "Opened", info, dateTime]); | |
}catch(exc){ | |
var rowData = sheet.appendRow(["asd", "asd", "asd", "asd", "0"]); | |
// If error occurs, throw exception | |
result = {"Status": "FAILED", "Message": exc}; | |
} | |
// Return result | |
return result; | |
} | |
function test(){ | |
var Name = "Saamer" | |
var Email = "[email protected]" | |
var Message = "This is a web Message" | |
var myJSObject='{"Name": "' + Name + '", "Email" : "' + Email + '", "Message" : "' + Message + '"}'; | |
var result = processResult(JSON.parse(myJSObject)) | |
console.log(result) | |
} | |
function testGet(){ | |
var e = { "queryString" : "src=Hel"} | |
var result = processRequest(e) | |
console.log(result) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment