Hello @Nour_Hassaine je t’explique comment mettre ça en place en 1 min (n’hésite pas mettre en résolu ^^)
3 étapes :
---------------1---------------
Dans un google sheet, menu extension → Apps Script
Colle ce code (remplace ta clé API)
var apiKey = <API KEY HERE>;
function fetchCampaigns() {
var limit = 25; // Number of items to fetch per request
var offset = 0; // Initial offset
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("campaigns");
// Clear existing data in the sheet
sheet.clear();
// Add headers
sheet.appendRow(["ID", "Name", "Status", "Activated","Activated Percent", "Replied","Replied Percent", "Won Percent","Won", "Lost","Lost Percent", "Step name", "Step sent", "Step opened", "Step opened Percent", "Step clicked","Step clicked Percent", "Step replied","Step replied Percent", "Step bounced","Step bounced Percent"]);
var totalCampaigns = 0;
var campaigns = [];
do {
var url = 'https://apiv2.lagrowthmachine.com/flow/campaigns?apikey=' + apiKey + '&skip=' + offset + '&limit=' + limit;
var options = {
'method': 'get',
'followRedirects': true
};
var response = UrlFetchApp.fetch(url, options);
var content = response.getContentText();
var data = JSON.parse(content);
if (data && data.campaigns) {
totalCampaigns = data.total; // Total number of campaigns available
for (var i = 0; i < data.campaigns.length; i++) {
var campaign = data.campaigns[i];
var campaignInfo = {
'id': campaign.id,
'name': campaign.name,
'status': campaign.status
};
campaigns.push(campaignInfo);
}
}
offset += limit; // Move to the next page
} while (offset < totalCampaigns);
// Add campaign data to the sheet
for (var i = 0; i < campaigns.length; i++) {
var campaign = campaigns[i];
var campaignStats = getCampaignStats(campaign.id);
var campaignOverallStats = campaignStats[0];
var templates = campaignStats[1];
var activated = campaignOverallStats.activated.total;
var activatedP = campaignOverallStats.activated.audiencePercent;
var replied = campaignOverallStats.replied.total;
var repliedP = campaignOverallStats.replied.audiencePercent;
var won = campaignOverallStats.won.total;
var wonP = campaignOverallStats.won.audiencePercent;
var lost = campaignOverallStats.lost.total;
var lostP = campaignOverallStats.lost.audiencePercent;
if (templates.length == 0) {
var newRow = [campaign.id, campaign.name, campaign.status, activated, replied, won, lost, "", "", "", "", "", ""];
sheet.appendRow(newRow);
} else {
for (var j = 0; j < campaignStats[1].length; j++) {
var stepname = campaignStats[1][j].name;
var stepsent = campaignStats[1][j].sent;
var stepopened = campaignStats[1][j].opened;
var stepopenedP = campaignStats[1][j].openedPercent;
var stepclicked = campaignStats[1][j].clicked;
var stepclickedP = campaignStats[1][j].clickedPercent;
var stepreplied = campaignStats[1][j].replied;
var steprepliedP = campaignStats[1][j].repliedPercent;
var stepbounced = campaignStats[1][j].bounced;
var stepbouncedP = campaignStats[1][j].bouncedPercent;
var newRow = [campaign.id, campaign.name, campaign.status, activated,activatedP, replied,repliedP, won,wonP, lost,lostP, stepname, stepsent, stepopened,stepopenedP, stepclicked,stepclickedP, stepreplied,steprepliedP, stepbounced,stepbouncedP];
sheet.appendRow(newRow);
}
}
}
}
function getCampaignStats(campaignId) {
var url = "https://apiv2.lagrowthmachine.com/flow/campaigns/" + campaignId + "/stats?apikey=" + apiKey;
var options = {
'method': 'get',
'contentType': 'application/json'
};
var response = UrlFetchApp.fetch(url, options);
var responseData = JSON.parse(response.getContentText());
var allStatus =responseData.engagementStats.status
var templates = responseData.engagementStats.templates
return [allStatus, templates]
}
---------------2---------------
Toujours dans Apps script, clique sur « Déclencheurs » dans le menu de gauche. (c’est une horloge).
Crée un déclencheur qui lance la fonction « fetchCampaigns » par exemple tous les jours à minuit
Fermez App script
---------------3---------------
Tous les jours, tu vas récupérer les données de tes campagnes LGM directement dans le sheet.
A toi de créer les graphs custom qui t’ intéressent,( ils se mettront à jour automatiquement tous les jours à minuit)
PS : modifie le script avec ChatGPT si besoin, je l’ai fait suivant mes besoins
Bonne journdée