Update campaign_results.min.js

pull/2990/head
BlkPh0x 2023-10-10 13:10:52 +11:00 committed by GitHub
parent 14bb02f2d2
commit 54781b920b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 73 deletions

View File

@ -291,87 +291,42 @@ function exportAsCleanCSV(scope) {
// Exports campaign results as a CSV file // Exports campaign results as a CSV file
function exportAsCSV(scope) { exportAsCSV(scope) {
var csvScope = null; exportHTML = $("#exportButton").html();
var filename = campaign.name + ' - ' + capitalize(scope) + '.csv'; var csvScope = null;
var filename = campaign.name + " - " + capitalize(scope) + ".csv";
switch (scope) { switch (scope) {
case "results": case "results":
csvScope = campaign.results; csvScope = campaign.results;
break; break;
case "events": case "events":
csvScope = campaign.timeline; csvScope = campaign.timeline;
break; break;
} }
if (!csvScope) { if (!csvScope) {
return; return;
} }
// Create an array to hold the CSV data $("#exportButton").html('<i class="fa fa-spinner fa-spin"></i>');
var csvData = [];
// Add the CSV header var csvString = Papa.unparse(csvScope, { escapeFormulae: true });
var header = ['Email', 'Email Opened', 'Clicked Link', 'Submitted Data']; var csvData = new Blob([csvString], { type: "text/csv;charset=utf-8;" });
csvData.push(header);
// Define a helper function to convert boolean to string if (navigator.msSaveBlob) {
function boolToString(value) { navigator.msSaveBlob(csvData, filename);
return value ? 'true' : 'false'; } else {
} var csvURL = window.URL.createObjectURL(csvData);
var dlLink = document.createElement("a");
// Add CSV rows for each entry in csvScope
csvScope.forEach(function (entry) {
var email = entry.email;
var status = entry.status;
// Initialize status flags
var emailOpened = false;
var clickedLink = false;
var submittedData = false;
// Update status flags based on the status value
switch (status) {
case 'Email Opened':
emailOpened = true;
break;
case 'Clicked Link':
emailOpened = true; // If clicked link, email is also opened
clickedLink = true;
break;
case 'Submitted Data':
emailOpened = true; // If submitted data, email is also opened
clickedLink = true; // If submitted data, link is also clicked
submittedData = true;
break;
}
// Add the CSV row
var csvRow = [email, boolToString(emailOpened), boolToString(clickedLink), boolToString(submittedData)];
csvData.push(csvRow);
});
// Convert the CSV data array to a CSV string
var csvString = csvData.map(function (row) {
return row.join(',');
}).join('\n');
// Create a Blob with the CSV string
var csvBlob = new Blob([csvString], {
type: 'text/csv;charset=utf-8;'
});
// Create a download link
var csvURL = window.URL.createObjectURL(csvBlob);
var dlLink = document.createElement('a');
dlLink.href = csvURL; dlLink.href = csvURL;
dlLink.setAttribute('download', filename); dlLink.setAttribute("download", filename);
document.body.appendChild(dlLink);
// Trigger the download
dlLink.click(); dlLink.click();
document.body.removeChild(dlLink);
}
// Clean up $("#exportButton").html(exportHTML);
window.URL.revokeObjectURL(csvURL);
} }
function replay(event_idx) { function replay(event_idx) {