-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from liberu-crm/sweep/Implement-Campaign-Perf…
…ormance-Reporting-and-Email-Tracking Implement Campaign Performance Reporting and Email Tracking
- Loading branch information
Showing
7 changed files
with
303 additions
and
1 deletion.
There are no files selected for viewing
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
65 changes: 65 additions & 0 deletions
65
app/Filament/App/Resources/MailchimpCampaignResource/Pages/ViewCampaignPerformance.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Filament\App\Resources\MailchimpCampaignResource\Pages; | ||
|
||
use App\Filament\App\Resources\MailchimpCampaignResource; | ||
use App\Services\MailChimpService; | ||
use Filament\Resources\Pages\Page; | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
|
||
class ViewCampaignPerformance extends Page | ||
{ | ||
protected static string $resource = MailchimpCampaignResource::class; | ||
|
||
protected static string $view = 'filament.app.resources.mailchimp-campaign-resource.pages.view-campaign-performance'; | ||
|
||
public function getTitle(): string | ||
{ | ||
return "Campaign Performance: {$this->record->name}"; | ||
} | ||
|
||
public function table(Table $table): Table | ||
{ | ||
$mailChimpService = app(MailChimpService::class); | ||
$report = $mailChimpService->getCampaignReport($this->record->id); | ||
|
||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('metric') | ||
->label('Metric'), | ||
Tables\Columns\TextColumn::make('value') | ||
->label('Value'), | ||
]) | ||
->contents([ | ||
[ | ||
'metric' => 'Emails Sent', | ||
'value' => $report['emails_sent'], | ||
], | ||
[ | ||
'metric' => 'Unique Opens', | ||
'value' => $report['unique_opens'], | ||
], | ||
[ | ||
'metric' => 'Open Rate', | ||
'value' => number_format($report['open_rate'] * 100, 2) . '%', | ||
], | ||
[ | ||
'metric' => 'Clicks', | ||
'value' => $report['clicks'], | ||
], | ||
[ | ||
'metric' => 'Click Rate', | ||
'value' => number_format($report['click_rate'] * 100, 2) . '%', | ||
], | ||
[ | ||
'metric' => 'Unsubscribes', | ||
'value' => $report['unsubscribes'], | ||
], | ||
[ | ||
'metric' => 'Bounce Rate', | ||
'value' => number_format($report['bounce_rate'] * 100, 2) . '%', | ||
], | ||
]); | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use Tests\TestCase; | ||
use App\Services\MailChimpService; | ||
use Mockery; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class CampaignPerformanceReportTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
protected $mailChimpService; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->mailChimpService = Mockery::mock(MailChimpService::class)->makePartial(); | ||
$this->app->instance(MailChimpService::class, $this->mailChimpService); | ||
} | ||
|
||
public function testGenerateCampaignPerformanceReport() | ||
{ | ||
$mockReport = [ | ||
'campaign_id' => 'campaign_123', | ||
'emails_sent' => 1000, | ||
'unique_opens' => 500, | ||
'open_rate' => 0.5, | ||
'clicks' => 200, | ||
'click_rate' => 0.2, | ||
'unsubscribes' => 10, | ||
'bounce_rate' => 0.02, | ||
]; | ||
|
||
$this->mailChimpService->shouldReceive('getCampaignReport') | ||
->once() | ||
->with('campaign_123') | ||
->andReturn($mockReport); | ||
|
||
$response = $this->get('/reports/campaign-performance/campaign_123'); | ||
|
||
$response->assertStatus(200); | ||
$response->assertViewIs('reports.email-campaign-performance'); | ||
$response->assertViewHas('data', $mockReport); | ||
$response->assertSee('Campaign Performance: campaign_123'); | ||
$response->assertSee('Emails Sent: 1,000'); | ||
$response->assertSee('Open Rate: 50.00%'); | ||
$response->assertSee('Click Rate: 20.00%'); | ||
} | ||
|
||
public function testGenerateABTestResultsReport() | ||
{ | ||
$mockResults = [ | ||
'campaign_id' => 'campaign_123', | ||
'subject_a' => 'Subject A', | ||
'subject_b' => 'Subject B', | ||
'opens_a' => 300, | ||
'opens_b' => 200, | ||
'clicks_a' => 150, | ||
'clicks_b' => 100, | ||
'winner' => 'a', | ||
'winning_metric' => 'opens', | ||
'winning_metric_value' => 300, | ||
]; | ||
|
||
$this->mailChimpService->shouldReceive('getABTestResults') | ||
->once() | ||
->with('campaign_123') | ||
->andReturn($mockResults); | ||
|
||
$response = $this->get('/reports/ab-test-results/campaign_123'); | ||
|
||
$response->assertStatus(200); | ||
$response->assertViewIs('reports.ab-test-results'); | ||
$response->assertViewHas('data', $mockResults); | ||
$response->assertSee('A/B Test Results for Campaign: campaign_123'); | ||
$response->assertSee('Subject A: Subject A'); | ||
|
||
$response->assertSee('Subject B: Subject B'); | ||
$response->assertSee('Opens A: 300'); | ||
$response->assertSee('Opens B: 200'); | ||
$response->assertSee('Clicks A: 150'); | ||
$response->assertSee('Clicks B: 100'); | ||
$response->assertSee('Winner: Version A'); | ||
$response->assertSee('Winning Metric: Opens'); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
Mockery::close(); | ||
parent::tearDown(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
use Tests\TestCase; | ||
use App\Services\GmailService; | ||
use App\Services\MailChimpService; | ||
use App\Models\Email; | ||
use Mockery; | ||
use Google_Service_Gmail_Message; | ||
|
@@ -16,12 +17,15 @@ class EmailTrackingIntegrationTest extends TestCase | |
use RefreshDatabase; | ||
|
||
protected $gmailService; | ||
protected $mailChimpService; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->gmailService = Mockery::mock(GmailService::class)->makePartial(); | ||
$this->mailChimpService = Mockery::mock(MailChimpService::class)->makePartial(); | ||
$this->app->instance(GmailService::class, $this->gmailService); | ||
$this->app->instance(MailChimpService::class, $this->mailChimpService); | ||
} | ||
|
||
public function testEmailTrackingIntegration() | ||
|
@@ -66,6 +70,54 @@ public function testEmailTrackingIntegration() | |
$response->assertSee('[email protected]'); | ||
} | ||
|
||
public function testEmailOpenTracking() | ||
{ | ||
$this->mailChimpService->shouldReceive('trackEmailOpen') | ||
->once() | ||
->with('campaign_123', 'email_456') | ||
->andReturn(true); | ||
|
||
$response = $this->get('/track-open/campaign_123/email_456'); | ||
$response->assertStatus(200); | ||
} | ||
|
||
public function testEmailClickTracking() | ||
{ | ||
$this->mailChimpService->shouldReceive('trackEmailClick') | ||
->once() | ||
->with('campaign_123', 'email_456', 'https://example.com') | ||
->andReturn(true); | ||
|
||
$response = $this->get('/track-click/campaign_123/email_456?url=https://example.com'); | ||
$response->assertStatus(200); | ||
} | ||
|
||
public function testCampaignPerformanceReport() | ||
{ | ||
$mockReport = [ | ||
'campaign_id' => 'campaign_123', | ||
'emails_sent' => 1000, | ||
'unique_opens' => 500, | ||
'open_rate' => 0.5, | ||
'clicks' => 200, | ||
'click_rate' => 0.2, | ||
'unsubscribes' => 10, | ||
'bounce_rate' => 0.02, | ||
]; | ||
|
||
$this->mailChimpService->shouldReceive('getCampaignReport') | ||
->once() | ||
->with('campaign_123') | ||
->andReturn($mockReport); | ||
|
||
$response = $this->get('/reports/campaign-performance/campaign_123'); | ||
$response->assertStatus(200); | ||
$response->assertSee('Campaign Performance: campaign_123'); | ||
$response->assertSee('Emails Sent: 1000'); | ||
$response->assertSee('Open Rate: 50%'); | ||
$response->assertSee('Click Rate: 20%'); | ||
} | ||
|
||
protected function createMockMessage() | ||
{ | ||
$message = Mockery::mock(Google_Service_Gmail_Message::class); | ||
|
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