// Data for both periods const data = { period1: { name: "Oct 31 - Nov 4", color: "#3B82F6", countries: [ { name: "USA", impressions: 647604, clicks: 41572, installs: 8440, cost: 20893.51, cpi: 2.48, cpm: 32.26, ctr: 6, conversion: 20, engagement: 0.12 }, { name: "Philippines", impressions: 7913019, clicks: 641406, installs: 28131, cost: 11822.74, cpi: 0.42, cpm: 1.49, ctr: 8, conversion: 4, engagement: 8.40 }, { name: "Canada", impressions: 165220, clicks: 7387, installs: 938, cost: 2240.25, cpi: 2.39, cpm: 13.56, ctr: 4, conversion: 13, engagement: 0.12 }, { name: "Australia", impressions: 25441, clicks: 1008, installs: 156, cost: 333.37, cpi: 2.14, cpm: 13.10, ctr: 4, conversion: 15, engagement: 42.80 }, { name: "India", impressions: 15609664, clicks: 2005750, installs: 148670, cost: 10071.26, cpi: 0.07, cpm: 0.65, ctr: 13, conversion: 7, engagement: 1.40 }, { name: "Ireland + UK", impressions: 70418, clicks: 2067, installs: 257, cost: 359.85, cpi: 1.40, cpm: 5.11, ctr: 3, conversion: 12, engagement: 28.00 }, { name: "Kenya + Nigeria", impressions: 330143, clicks: 17439, installs: 2523, cost: 371.25, cpi: 0.15, cpm: 1.12, ctr: 5, conversion: 14, engagement: 3.00 }, { name: "Rome & Vatican", impressions: 20093, clicks: 1613, installs: 391, cost: 358.53, cpi: 0.92, cpm: 17.84, ctr: 8, conversion: 24, engagement: 18.40 } ] }, period2: { name: "Nov 5 - Nov 9", color: "#8B5CF6", countries: [ { name: "USA", impressions: 667674, clicks: 42384, installs: 11245, cost: 22060.61, cpi: 1.96, cpm: 33.04, ctr: 6, conversion: 27, engagement: 0.10 }, { name: "Philippines", impressions: 402596, clicks: 37144, installs: 1988, cost: 350.62, cpi: 0.18, cpm: 0.87, ctr: 9, conversion: 5, engagement: 3.60 }, { name: "Canada", impressions: 500450, clicks: 24861, installs: 3807, cost: 9207.12, cpi: 2.42, cpm: 18.40, ctr: 5, conversion: 15, engagement: 0.12 }, { name: "Australia", impressions: 29938, clicks: 1269, installs: 175, cost: 309.04, cpi: 1.77, cpm: 10.32, ctr: 4, conversion: 14, engagement: 35.40 }, { name: "India", impressions: 18474778, clicks: 2236265, installs: 158600, cost: 10428.98, cpi: 0.07, cpm: 0.56, ctr: 12, conversion: 7, engagement: 1.40 }, { name: "Ireland + UK", impressions: 75206, clicks: 2495, installs: 233, cost: 372.93, cpi: 1.60, cpm: 4.96, ctr: 3, conversion: 9, engagement: 32.00 }, { name: "Kenya + Nigeria", impressions: 446291, clicks: 19682, installs: 2498, cost: 363.62, cpi: 0.15, cpm: 0.81, ctr: 4, conversion: 13, engagement: 3.00 }, { name: "Rome & Vatican", impressions: 31382, clicks: 2074, installs: 335, cost: 370.72, cpi: 1.11, cpm: 11.81, ctr: 7, conversion: 16, engagement: 22.20 } ] } }; // Initialize charts let costChart; let installsChart; let ctrChart; let cpiChart; document.addEventListener('DOMContentLoaded', function() { // Initialize charts createCostChart(); createInstallsChart(); createCTRChart(); createCPIChart(); populateTable(); }); function createCostChart() { const ctx = document.getElementById('costChart').getContext('2d'); const labels = data.period1.countries.map(country => country.name); const period1Data = data.period1.countries.map(country => country.cost); const period2Data = data.period2.countries.map(country => country.cost); costChart = new Chart(ctx, { type: 'bar', data: { labels: labels, datasets: [ { label: data.period1.name, data: period1Data, backgroundColor: data.period1.color, borderColor: data.period1.color, borderWidth: 1 }, { label: data.period2.name, data: period2Data, backgroundColor: data.period2.color, borderColor: data.period2.color, borderWidth: 1 } ] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, ticks: { callback: function(value) { return ' function createCTRChart() { const ctx = document.getElementById('ctrChart').getContext('2d'); const labels = data.period1.countries.map(country => country.name); const period1Data = data.period1.countries.map(country => country.ctr); const period2Data = data.period2.countries.map(country => country.ctr); ctrChart = new Chart(ctx, { type: 'bar', data: { labels: labels, datasets: [ { label: data.period1.name, data: period1Data, backgroundColor: data.period1.color, borderColor: data.period1.color, borderWidth: 1 }, { label: data.period2.name, data: period2Data, backgroundColor: data.period2.color, borderColor: data.period2.color, borderWidth: 1 } ] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, ticks: { callback: function(value) { return value + '%'; } } } }, plugins: { tooltip: { callbacks: { label: function(context) { return `${context.dataset.label}: ${context.raw}%`; } } }, legend: { position: 'top', } } } }); } function createCPIChart() { const ctx = document.getElementById('cpiChart').getContext('2d'); const labels = data.period1.countries.map(country => country.name); const period1Data = data.period1.countries.map(country => country.cpi); const period2Data = data.period2.countries.map(country => country.cpi); cpiChart = new Chart(ctx, { type: 'bar', data: { labels: labels, datasets: [ { label: data.period1.name, data: period1Data, backgroundColor: data.period1.color, borderColor: data.period1.color, borderWidth: 1 }, { label: data.period2.name, data: period2Data, backgroundColor: data.period2.color, borderColor: data.period2.color, borderWidth: 1 } ] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, ticks: { callback: function(value) { return 'const installsTableBody = document.getElementById('installsTableBody'); const costTableBody = document.getElementById('costTableBody'); installsTableBody.innerHTML = ''; costTableBody.innerHTML = ''; data.period1.countries.forEach((country, index) => { // Calculate changes const installsChange = data.period2.countries[index].installs - data.period1.countries[index].installs; const costChange = data.period2.countries[index].cost - data.period1.countries[index].cost; // Installs table row const installsRow = document.createElement('tr'); installsRow.innerHTML = ` ${country.name} ${new Intl.NumberFormat().format(data.period1.countries[index].installs)} ${new Intl.NumberFormat().format(data.period2.countries[index].installs)} ${installsChange >= 0 ? '+' : ''}${new Intl.NumberFormat().format(installsChange)} `; installsTableBody.appendChild(installsRow); // Cost table row const costRow = document.createElement('tr'); costRow.innerHTML = ` ${country.name} ${data.period1.countries[index].cost.toFixed(2)} ${data.period2.countries[index].cost.toFixed(2)} ${costChange >= 0 ? '+' : ''}${Math.abs(costChange).toFixed(2)} `; costTableBody.appendChild(costRow); }); } + value.toFixed(2); } } } }, plugins: { tooltip: { callbacks: { label: function(context) { return `${context.dataset.label}: ${context.raw.toFixed(2)}`; } } }, legend: { position: 'top', } } } }); } function createInstallsChart() { const ctx = document.getElementById('installsChart').getContext('2d'); const labels = data.period1.countries.map(country => country.name); const period1Data = data.period1.countries.map(country => country.installs); const period2Data = data.period2.countries.map(country => country.installs); installsChart = new Chart(ctx, { type: 'bar', data: { labels: labels, datasets: [ { label: data.period1.name, data: period1Data, backgroundColor: data.period1.color, borderColor: data.period1.color, borderWidth: 1 }, { label: data.period2.name, data: period2Data, backgroundColor: data.period2.color, borderColor: data.period2.color, borderWidth: 1 } ] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, ticks: { callback: function(value) { return new Intl.NumberFormat().format(value); } } } }, plugins: { tooltip: { callbacks: { label: function(context) { return `${context.dataset.label}: ${new Intl.NumberFormat().format(context.raw)}`; } } }, legend: { position: 'top', } } } }); } function getMetricTitle(metric) { const titles = { impressions: 'Impressions', clicks: 'Clicks', installs: 'Installs', cost: 'Cost ($)', cpi: 'Cost Per Install ($)', ctr: 'Click Through Rate (%)' }; return titles[metric] || metric; } function populateTable() { const installsTableBody = document.getElementById('installsTableBody'); const costTableBody = document.getElementById('costTableBody'); installsTableBody.innerHTML = ''; costTableBody.innerHTML = ''; data.period1.countries.forEach((country, index) => { // Calculate changes const installsChange = data.period2.countries[index].installs - data.period1.countries[index].installs; const costChange = data.period2.countries[index].cost - data.period1.countries[index].cost; // Installs table row const installsRow = document.createElement('tr'); installsRow.innerHTML = ` ${country.name} ${new Intl.NumberFormat().format(data.period1.countries[index].installs)} ${new Intl.NumberFormat().format(data.period2.countries[index].installs)} ${installsChange >= 0 ? '+' : ''}${new Intl.NumberFormat().format(installsChange)} `; installsTableBody.appendChild(installsRow); // Cost table row const costRow = document.createElement('tr'); costRow.innerHTML = ` ${country.name} ${data.period1.countries[index].cost.toFixed(2)} ${data.period2.countries[index].cost.toFixed(2)} ${costChange >= 0 ? '+' : ''}${Math.abs(costChange).toFixed(2)} `; costTableBody.appendChild(costRow); }); } + value.toFixed(2); } } } }, plugins: { tooltip: { callbacks: { label: function(context) { return `${context.dataset.label}: ${context.raw.toFixed(2)}`; } } }, legend: { position: 'top', } } } }); } function populateTable() { const installsTableBody = document.getElementById('installsTableBody'); const costTableBody = document.getElementById('costTableBody'); installsTableBody.innerHTML = ''; costTableBody.innerHTML = ''; data.period1.countries.forEach((country, index) => { // Calculate changes const installsChange = data.period2.countries[index].installs - data.period1.countries[index].installs; const costChange = data.period2.countries[index].cost - data.period1.countries[index].cost; // Installs table row const installsRow = document.createElement('tr'); installsRow.innerHTML = ` ${country.name} ${new Intl.NumberFormat().format(data.period1.countries[index].installs)} ${new Intl.NumberFormat().format(data.period2.countries[index].installs)} ${installsChange >= 0 ? '+' : ''}${new Intl.NumberFormat().format(installsChange)} `; installsTableBody.appendChild(installsRow); // Cost table row const costRow = document.createElement('tr'); costRow.innerHTML = ` ${country.name} ${data.period1.countries[index].cost.toFixed(2)} ${data.period2.countries[index].cost.toFixed(2)} ${costChange >= 0 ? '+' : ''}${Math.abs(costChange).toFixed(2)} `; costTableBody.appendChild(costRow); }); } + value.toFixed(2); } } } }, plugins: { tooltip: { callbacks: { label: function(context) { return `${context.dataset.label}: ${context.raw.toFixed(2)}`; } } }, legend: { position: 'top', } } } }); } function createInstallsChart() { const ctx = document.getElementById('installsChart').getContext('2d'); const labels = data.period1.countries.map(country => country.name); const period1Data = data.period1.countries.map(country => country.installs); const period2Data = data.period2.countries.map(country => country.installs); installsChart = new Chart(ctx, { type: 'bar', data: { labels: labels, datasets: [ { label: data.period1.name, data: period1Data, backgroundColor: data.period1.color, borderColor: data.period1.color, borderWidth: 1 }, { label: data.period2.name, data: period2Data, backgroundColor: data.period2.color, borderColor: data.period2.color, borderWidth: 1 } ] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, ticks: { callback: function(value) { return new Intl.NumberFormat().format(value); } } } }, plugins: { tooltip: { callbacks: { label: function(context) { return `${context.dataset.label}: ${new Intl.NumberFormat().format(context.raw)}`; } } }, legend: { position: 'top', } } } }); } function getMetricTitle(metric) { const titles = { impressions: 'Impressions', clicks: 'Clicks', installs: 'Installs', cost: 'Cost ($)', cpi: 'Cost Per Install ($)', ctr: 'Click Through Rate (%)' }; return titles[metric] || metric; } function populateTable() { const installsTableBody = document.getElementById('installsTableBody'); const costTableBody = document.getElementById('costTableBody'); installsTableBody.innerHTML = ''; costTableBody.innerHTML = ''; data.period1.countries.forEach((country, index) => { // Calculate changes const installsChange = data.period2.countries[index].installs - data.period1.countries[index].installs; const costChange = data.period2.countries[index].cost - data.period1.countries[index].cost; // Installs table row const installsRow = document.createElement('tr'); installsRow.innerHTML = ` ${country.name} ${new Intl.NumberFormat().format(data.period1.countries[index].installs)} ${new Intl.NumberFormat().format(data.period2.countries[index].installs)} ${installsChange >= 0 ? '+' : ''}${new Intl.NumberFormat().format(installsChange)} `; installsTableBody.appendChild(installsRow); // Cost table row const costRow = document.createElement('tr'); costRow.innerHTML = ` ${country.name} ${data.period1.countries[index].cost.toFixed(2)} ${data.period2.countries[index].cost.toFixed(2)} ${costChange >= 0 ? '+' : ''}${Math.abs(costChange).toFixed(2)} `; costTableBody.appendChild(costRow); }); }