Add CLI script to fetch active Meta Ads insights for campaigns, adsets, and ads

- Implemented a new PHP script to retrieve insights for the last N days (default 30).
- Supports command-line options for token, account ID, days, API version, and output file.
- Fetches data at campaign, adset, and ad levels, with filtering for active statuses.
- Handles JSON output and optional file saving, including directory creation if necessary.
- Includes error handling for cURL requests and JSON responses.
This commit is contained in:
2026-02-20 23:45:36 +01:00
parent 167ced3573
commit b54a9a71b1
34 changed files with 8516 additions and 1676 deletions

View File

@@ -36,9 +36,15 @@
</div>
<div class="campaigns-table-wrap">
<div id="history_bulk_actions" style="display:none; margin-bottom: 10px;">
<button type="button" id="delete_history_entries" class="btn btn-danger btn-sm">
<i class="fa-solid fa-trash"></i> Usun zaznaczone (<span id="history_selected_count">0</span>)
</button>
</div>
<table class="table" id="products">
<thead>
<tr>
<th style="width: 30px; text-align: center;"><input type="checkbox" id="select_all_history"></th>
<th>Data</th>
<th>ROAS (30 dni)</th>
<th>ROAS (all time)</th>
@@ -468,6 +474,8 @@ $( function()
$( '#products' ).DataTable().destroy();
$( '#products tbody' ).empty();
}
$( '#history_bulk_actions' ).hide();
$( '#select_all_history' ).prop( 'checked', false );
if ( vals.length === 1 )
{
@@ -485,6 +493,7 @@ $( function()
lengthChange: false,
pageLength: 15,
columns: [
{ width: '30px', orderable: false, className: 'dt-center', searchable: false },
{ width: '130px', name: 'date', orderable: false, className: "nowrap" },
{ width: '120px', name: 'roas30', orderable: false, className: "dt-type-numeric" },
{ width: '120px', name: 'roas_all_time', orderable: false, className: "dt-type-numeric" },
@@ -518,6 +527,93 @@ $( function()
}
});
// --- Checkboxy historii: select all, licznik, bulk delete ---
function updateHistoryBulkActions()
{
var checked = $( '#products .history-check:checked' );
var count = checked.length;
$( '#history_selected_count' ).text( count );
$( '#history_bulk_actions' ).toggle( count > 0 );
}
$( 'body' ).on( 'change', '#select_all_history', function()
{
var isChecked = this.checked;
$( '#products .history-check' ).prop( 'checked', isChecked );
updateHistoryBulkActions();
});
$( 'body' ).on( 'change', '.history-check', function()
{
var all = $( '#products .history-check' );
var checked = $( '#products .history-check:checked' );
$( '#select_all_history' ).prop( 'checked', all.length > 0 && all.length === checked.length );
updateHistoryBulkActions();
});
$( 'body' ).on( 'draw.dt', '#products', function()
{
$( '#select_all_history' ).prop( 'checked', false );
updateHistoryBulkActions();
});
$( 'body' ).on( 'click', '#delete_history_entries', function()
{
var ids = [];
$( '#products .history-check:checked' ).each( function() {
ids.push( $( this ).val() );
});
if ( !ids.length ) return;
$.confirm({
title: 'Potwierdzenie usuniecia',
content: 'Czy na pewno chcesz usunac <strong>' + ids.length + '</strong> ' + ( ids.length === 1 ? 'wpis' : 'wpisow' ) + ' z historii?<br>Ta operacja jest nieodwracalna.',
type: 'red',
buttons: {
confirm: {
text: 'Usun (' + ids.length + ')',
btnClass: 'btn-red',
keys: ['enter'],
action: function()
{
$.ajax({
url: '/campaigns/delete_history_entries/',
type: 'POST',
data: { ids: ids },
success: function( response )
{
var data = JSON.parse( response );
if ( data.success )
{
$.alert({
title: 'Sukces',
content: 'Usunieto ' + data.deleted + ' ' + ( data.deleted === 1 ? 'wpis' : 'wpisow' ) + '.',
type: 'green',
autoClose: 'ok|2000'
});
if ( $.fn.DataTable.isDataTable( '#products' ) )
$( '#products' ).DataTable().ajax.reload( null, false );
reloadChart();
}
else
{
$.alert({
title: 'Blad',
content: data.message || 'Nie udalo sie usunac wpisow.',
type: 'red'
});
}
}
});
}
},
cancel: { text: 'Anuluj' }
}
});
});
var saved_client_id = storage_get( STORAGE_CLIENT_KEY );
var saved_campaign_id = storage_get( STORAGE_CAMPAIGN_KEY );