From 57444164a02e97ab1be0f0c305b07669fe024c86 Mon Sep 17 00:00:00 2001 From: Maru Amallo-amamarul Date: Wed, 7 Sep 2016 17:31:56 -0300 Subject: [PATCH 01/11] Add Url Clicked Tracking Migration, Model and controller --- ..._03_01_193027_create_sent_emails_table.php | 2 +- ...7_create_sent_emails_Url_Clicked_table.php | 35 +++++++++++++++++++ src/MailTrackerController.php | 11 ++++++ src/Model/SentEmailUrlClicked.php | 22 ++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php create mode 100644 src/Model/SentEmailUrlClicked.php diff --git a/migrations/2016_03_01_193027_create_sent_emails_table.php b/migrations/2016_03_01_193027_create_sent_emails_table.php index 96daa7a..35b1194 100644 --- a/migrations/2016_03_01_193027_create_sent_emails_table.php +++ b/migrations/2016_03_01_193027_create_sent_emails_table.php @@ -14,7 +14,6 @@ public function up() { Schema::create('sent_emails', function (Blueprint $table) { $table->increments('id'); - $table->timestamps(); $table->char('hash',32)->unique(); $table->text('headers'); $table->string('sender'); @@ -23,6 +22,7 @@ public function up() $table->text('content'); $table->integer('opens'); $table->integer('clicks'); + $table->timestamps(); }); } diff --git a/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php b/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php new file mode 100644 index 0000000..72f7dd6 --- /dev/null +++ b/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->integer('sent_email_id'); + $table->foreign('sent_email_id')->references('id')->on('sent_emails')->onDelete('cascade'); + $table->string('url'); + $table->char('hash',32); + $table->integer('clicks')->default('1'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('sent_emails'); + } +} diff --git a/src/MailTrackerController.php b/src/MailTrackerController.php index f99107d..4b39026 100644 --- a/src/MailTrackerController.php +++ b/src/MailTrackerController.php @@ -45,6 +45,17 @@ public function getL($url, $hash) if($tracker) { $tracker->clicks++; $tracker->save(); + $url_clicked = Model\SentEmailUrlClicked::where('url',$url)->where('hash', $hash)->first(); + if ($url_clicked) { + $url_clicked->clicks++; + $url_clicked->save(); + } else { + $url_clicked = Model\SentEmailUrlClicked::create([ + 'sent_email_id' => $tracker->id, + 'url' => $url, + 'hash' => $hash, + ]); + } Event::fire(new LinkClickedEvent($tracker)); } diff --git a/src/Model/SentEmailUrlClicked.php b/src/Model/SentEmailUrlClicked.php new file mode 100644 index 0000000..f2a8ea9 --- /dev/null +++ b/src/Model/SentEmailUrlClicked.php @@ -0,0 +1,22 @@ +belongsTo(SentEmail::class,'sent_email_id'); + } +} From 0493e0290dfadb9faea9ab3214bfe4d014dcefa9 Mon Sep 17 00:00:00 2001 From: Maru Amallo-amamarul Date: Wed, 7 Sep 2016 17:52:57 -0300 Subject: [PATCH 02/11] Correction on table sent_emails_url_clicked --- .../2016_09_07_193027_create_sent_emails_Url_Clicked_table.php | 2 +- src/MailTrackerController.php | 2 +- src/Model/SentEmailUrlClicked.php | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php b/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php index 72f7dd6..2302a6c 100644 --- a/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php +++ b/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php @@ -14,7 +14,7 @@ public function up() { Schema::create('sent_emails_url_clicked', function (Blueprint $table) { $table->increments('id'); - $table->integer('sent_email_id'); + $table->integer('sent_email_id')->unsigned(); $table->foreign('sent_email_id')->references('id')->on('sent_emails')->onDelete('cascade'); $table->string('url'); $table->char('hash',32); diff --git a/src/MailTrackerController.php b/src/MailTrackerController.php index 4b39026..f84fcd7 100644 --- a/src/MailTrackerController.php +++ b/src/MailTrackerController.php @@ -53,7 +53,7 @@ public function getL($url, $hash) $url_clicked = Model\SentEmailUrlClicked::create([ 'sent_email_id' => $tracker->id, 'url' => $url, - 'hash' => $hash, + 'hash' => $tracker->hash, ]); } Event::fire(new LinkClickedEvent($tracker)); diff --git a/src/Model/SentEmailUrlClicked.php b/src/Model/SentEmailUrlClicked.php index f2a8ea9..d5bea01 100644 --- a/src/Model/SentEmailUrlClicked.php +++ b/src/Model/SentEmailUrlClicked.php @@ -3,7 +3,7 @@ namespace jdavidbakr\MailTracker\Model; use Illuminate\Database\Eloquent\Model; -use Model\SentEmail; +// use Model\SentEmail; class SentEmailUrlClicked extends Model { @@ -12,6 +12,7 @@ class SentEmailUrlClicked extends Model protected $fillable = [ 'sent_email_id', 'url', + 'hash', 'clicks', ]; From 33c74e91474928d441cd0a1f6682ca486cf682e6 Mon Sep 17 00:00:00 2001 From: Maru Amallo-amamarul Date: Thu, 8 Sep 2016 00:36:00 -0300 Subject: [PATCH 03/11] new migration added to publishes --- src/MailTrackerServiceProvider.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/MailTrackerServiceProvider.php b/src/MailTrackerServiceProvider.php index 42e31ad..5f4de06 100644 --- a/src/MailTrackerServiceProvider.php +++ b/src/MailTrackerServiceProvider.php @@ -9,10 +9,10 @@ class MailTrackerServiceProvider extends ServiceProvider { /** * Check to see if we're using lumen or laravel. - * + * * @return bool */ - public function isLumen() + public function isLumen() { $lumenClass = 'Laravel\Lumen\Application'; return ($this->app instanceof $lumenClass); @@ -33,6 +33,9 @@ public function boot() $this->publishes([ __DIR__.'/../migrations/2016_03_01_193027_create_sent_emails_table.php' => database_path('migrations/2016_03_01_193027_create_sent_emails_table.php') ], 'config'); + $this->publishes([ + __DIR__.'/../migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php' => database_path('migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php') + ], 'config'); } // Hook into the mailer From a4373bde7e706ffa434763b0f6daa165a021078e Mon Sep 17 00:00:00 2001 From: Maru Amallo-amamarul Date: Thu, 8 Sep 2016 01:01:59 -0300 Subject: [PATCH 04/11] migration sent_emails_url_clicked drop table --- .../2016_09_07_193027_create_sent_emails_Url_Clicked_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php b/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php index 2302a6c..1b161b0 100644 --- a/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php +++ b/migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php @@ -30,6 +30,6 @@ public function up() */ public function down() { - Schema::drop('sent_emails'); + Schema::drop('sent_emails_url_clicked'); } } From 0f84a141f54c14c91bd0aff250163282064c02ba Mon Sep 17 00:00:00 2001 From: Maru Amallo-amamarul Date: Sat, 10 Sep 2016 16:16:41 -0300 Subject: [PATCH 05/11] Admin Panel and something more config options added README Admin Controller Views for emails and admin panel. --- README.md | 16 +- config/mail-tracker.php | 34 +++- src/AdminController.php | 89 ++++++++++ src/MailTrackerServiceProvider.php | 29 +++- src/views/email_form.blade.php | 78 +++++++++ src/views/emails/mensaje.blade.php | 30 ++++ src/views/emails/mensaje_layout.blade.php | 195 ++++++++++++++++++++++ src/views/index.blade.php | 99 +++++++++++ src/views/layouts/app.blade.php | 11 ++ src/views/show.blade.php | 70 ++++++++ src/views/url_detail.blade.php | 90 ++++++++++ 11 files changed, 735 insertions(+), 6 deletions(-) create mode 100644 src/AdminController.php create mode 100644 src/views/email_form.blade.php create mode 100644 src/views/emails/mensaje.blade.php create mode 100644 src/views/emails/mensaje_layout.blade.php create mode 100644 src/views/index.blade.php create mode 100644 src/views/layouts/app.blade.php create mode 100644 src/views/show.blade.php create mode 100644 src/views/url_detail.blade.php diff --git a/README.md b/README.md index 20955ef..8027115 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,14 @@ $ php artisan migrate Once installed, all outgoing mail will be logged to the database. The following config options are available in config/mail-tracker.php: +* **name**: set your App Name. * **inject-pixel**: set to true to inject a tracking pixel into all outgoing html emails. * **track-links**: set to true to rewrite all anchor href links to include a tracking link. The link will take the user back to your website which will then redirect them to the final destination after logging the click. * **expire-days**: How long in days that an email should be retained in your database. If you are sending a lot of mail, you probably want it to eventually expire. Set it to zero to never purge old emails from the database. * **route**: The route information for the tracking URLs. Set the prefix and middlware as desired. -* **admin-route**: The route information for the admin. Set the prefix and middleware. *Note that this is not yet built.* +* **admin-route**: The route information for the admin. Set the prefix and middleware. +* **admin-template**: The params for the Admin Panel and Views. You can integrate your existing Admin Panel with the MailTracker admin panel. +* **date-format**: You can define the format to show dates in the Admin Panel. ## Events @@ -116,10 +119,17 @@ protected $listen = [ ], ]; ``` +## Views -## TODO +When you do the php artisan vendor:publish simple views will add to your resources/views/vendor/emailTrakingViews and you can customize. -Currently this plugin is only tracking the outgoing mail. There is no view yet to explore the existing data. +## Admin Panel + +The standard admin panel route is located at /email-manager. +You can customize your route in the config file. +You can see all sent emails, total opens, total urls clicks, show individuals emails and show the urls clicked details. +Also you can send emails from your admin panel. +All views (email tamplates, panel) can customize in resources/views/vendor/emailTrakingViews. ## Contributing diff --git a/config/mail-tracker.php b/config/mail-tracker.php index c9b559c..e6beb77 100644 --- a/config/mail-tracker.php +++ b/config/mail-tracker.php @@ -1,6 +1,20 @@ - 'Mail Tracker', + /** * To disable the pixel injection, set this to false. */ @@ -32,4 +46,22 @@ 'middleware' => 'super', ], + /** + * Admin Tamplate + * example + * 'name' => 'layouts.app' for Deafult emailTraking use 'emailTrakingViews::layouts.app' + * 'section' => 'content' for Deafult emailTraking use 'content' + * 'styles_section' => 'styles' for Deafult emailTraking use 'styles' + */ + 'admin-template' => [ + 'name' => 'emailTrakingViews::layouts.app', + 'section' => 'content', + 'styles_section' => 'styles', + ], + + /** + * Date Format + */ + 'date-format' => 'd/m/Y', + ]; diff --git a/src/AdminController.php b/src/AdminController.php new file mode 100644 index 0000000..98e7481 --- /dev/null +++ b/src/AdminController.php @@ -0,0 +1,89 @@ +with('emails', $emails); + } + + /** + * Show Email. + * + * @return \Illuminate\Http\Response + */ + public function getShowEmail($id) + { + $email = SentEmail::where('id',$id)->first(); + return \View('emailTrakingViews::show')->with('email', $email); + } + + /** + * Url Detail. + * + * @return \Illuminate\Http\Response + */ + public function getUrlDetail($id) + { + $detalle = SentEmailUrlClicked::where('sent_email_id',$id)->get(); + return \View('emailTrakingViews::url_detail')->with('details', $detalle); + } + + /** + * New Email. + * + * @return \Illuminate\Http\Response + */ + public function getNewEmail() + { + + return view('emailTrakingViews::email_form'); + } + + /** + * Send Email. + * + * @return \Illuminate\Http\Response + */ + public function getSendEmail(Request $request) + { + + $data = [ + 'name' => $request->name, + 'to' => $request->email, + 'message' => $request->message + ]; + Mail::send('emailTrakingViews::emails/mensaje', ['data' => $data], function($message) use ($data){ + $message->from(config('mail.from.address'), config('mail.from.name')); + $message->to($data['to'], $data['name']); + // $message->cc('cc@johndoe.com', 'CC Name'); + // $message->bcc('bcc@johndoe.com', 'BCC Name'); + // $message->replyTo('reply-to@johndoe.com', 'Reply-To Name'); + // $message->priority(3); + $message->subject('New Message from '. config('mail-tracker.name') ); + }); + \Log::notice('Email Sent to: '.$data['to'] . ' - '. $data['name']); + return redirect()->route('mailTracker_Index'); + } +} diff --git a/src/MailTrackerServiceProvider.php b/src/MailTrackerServiceProvider.php index 5f4de06..a668483 100644 --- a/src/MailTrackerServiceProvider.php +++ b/src/MailTrackerServiceProvider.php @@ -36,6 +36,10 @@ public function boot() $this->publishes([ __DIR__.'/../migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php' => database_path('migrations/2016_09_07_193027_create_sent_emails_Url_Clicked_table.php') ], 'config'); + $this->loadViewsFrom(__DIR__.'/views', 'emailTrakingViews'); + $this->publishes([ + __DIR__.'/views' => base_path('resources/views/vendor/emailTrakingViews'), + ]); } // Hook into the mailer @@ -48,8 +52,8 @@ public function boot() if (!$this->isLumen()) { Route::group($config, function() { - Route::get('t/{hash}', 'MailTrackerController@getT'); - Route::get('l/{url}/{hash}', 'MailTrackerController@getL'); + Route::get('t/{hash}', 'MailTrackerController@getT')->name('mailTracker_t'); + Route::get('l/{url}/{hash}', 'MailTrackerController@getL')->name('mailTracker_l'); }); } else { $app = $this->app; @@ -58,6 +62,27 @@ public function boot() $app->get('l', 'MailTrackerController@getL'); }); } + // Install the Admin routes + $config_admin = $this->app['config']->get('mail-tracker.admin-route', []); + $config_admin['namespace'] = 'jdavidbakr\MailTracker'; + + if (!$this->isLumen()) { + Route::group($config_admin, function() + { + Route::get('/', 'AdminController@getIndex')->name('mailTracker_Index'); + Route::get('show-email/{id}', 'AdminController@getShowEmail')->name('mailTracker_ShowEmail'); + Route::get('url-detail/{id}', 'AdminController@getUrlDetail')->name('mailTracker_UrlDetail'); + Route::get('new-email', 'AdminController@getNewEmail')->name('mailTracker_NewEmail'); + Route::get('send-email', 'AdminController@getSendEmail')->name('mailTracker_SendEmail'); + }); + } else { + $app = $this->app; + $app->group($config_admin, function () use ($app) { + $app->get('index', 'AdminController@getIndex'); + $app->get('example-email', 'AdminController@getExampleEmail'); + $app->get('url-detail', 'AdminController@getUrlDetail'); + }); + } } /** diff --git a/src/views/email_form.blade.php b/src/views/email_form.blade.php new file mode 100644 index 0000000..73fbc3b --- /dev/null +++ b/src/views/email_form.blade.php @@ -0,0 +1,78 @@ +@extends(config('mail-tracker.admin-template.name')) +@section('styles') + +@endsection +@section(config('mail-tracker.admin-template.section')) +

Mail Tracker

+
+ All Sent Emails +
+
+ New Mail +
+
+
+ Name:
+
+ Email:
+
+ Message:
+

+ +
+@endsection diff --git a/src/views/emails/mensaje.blade.php b/src/views/emails/mensaje.blade.php new file mode 100644 index 0000000..1e4dd69 --- /dev/null +++ b/src/views/emails/mensaje.blade.php @@ -0,0 +1,30 @@ +@extends('emailTrakingViews::emails/mensaje_layout') +@section('title') + Message from {{config('mail-tracker.name')}} +@endsection + +@section('preheader') + Message from {{config('mail-tracker.name')}}
+@endsection +@section('nombre_destinatario') + {{ $data['name'] }} +@endsection +@section('mensaje') +

Static Email Title

+

+ Static Email Content +

+ {{ $data['message'] }} +@endsection +@section('href_call_to_action') + {{env('APP_URL')}} +@endsection +@section('txt_call_to_action') + Call To Action +@endsection +@section('txt_extra') + This email comes from {{config('mail-tracker.name')}} +@endsection +@section('saludo_final') + Regards +@endsection diff --git a/src/views/emails/mensaje_layout.blade.php b/src/views/emails/mensaje_layout.blade.php new file mode 100644 index 0000000..1d1f0c4 --- /dev/null +++ b/src/views/emails/mensaje_layout.blade.php @@ -0,0 +1,195 @@ + + + + + + @yield('title') + + + + + + + + + +
  +
+ + + + + + + + + + + +
+ + + + + + + +
+ + {{config('mail-tracker.name')}} + +
+

Hi @yield('nombre_destinatario')

+

@yield('mensaje')

+ + + + + + +
+ + + + + + +
+ @yield('txt_call_to_action') + +
+
+

@yield('txt_extra')

+

@yield('saludo_final')

+
+
+ + + + + + +
+
 
+ + diff --git a/src/views/index.blade.php b/src/views/index.blade.php new file mode 100644 index 0000000..7549385 --- /dev/null +++ b/src/views/index.blade.php @@ -0,0 +1,99 @@ +@extends(config('mail-tracker.admin-template.name')) +@section(config('mail-tracker.admin-template.styles_section')) + +@endsection +@section(config('mail-tracker.admin-template.section')) +

Mail Tracker

+
+ New Mail +

+
+
+ + + + + + + + + + @foreach($emails as $email) + + + + + + + + + + + @endforeach +
RecipientSubjectOpensOpensClicksSend AtShow EmailUrl Report
{{$email->recipient}}{{$email->subject}}{{$email->opens > 0 ? 'OPENED' : 'NOT OPEN'}}{{$email->opens}}{{$email->clicks}}{{$email->created_at->format(config('mail-tracker.date-format'))}} + Show + + @if($email->clicks > 0) + Url Report + @else + Not Clicks + @endif +
+
+@endsection diff --git a/src/views/layouts/app.blade.php b/src/views/layouts/app.blade.php new file mode 100644 index 0000000..8f21d51 --- /dev/null +++ b/src/views/layouts/app.blade.php @@ -0,0 +1,11 @@ + + + + + Mail Tracker + @yield(config('mail-tracker.admin-template.styles_section')) + + + @yield('content') + + diff --git a/src/views/show.blade.php b/src/views/show.blade.php new file mode 100644 index 0000000..d998045 --- /dev/null +++ b/src/views/show.blade.php @@ -0,0 +1,70 @@ + + + + + Show Email + + + +

Mail Tracker

+

+ New Mail +

+ All Sent Emails +
+

Email ID {{$email->id}}

+ Recipient: {{$email->recipient}}
+ Subject: {{$email->subject}}
+ Sent At: {{$email->created_at->format(config('mail-tracker.date-format'))}} +

+ + + {!!$email->content!!} diff --git a/src/views/url_detail.blade.php b/src/views/url_detail.blade.php new file mode 100644 index 0000000..1e0fae3 --- /dev/null +++ b/src/views/url_detail.blade.php @@ -0,0 +1,90 @@ +@extends(config('mail-tracker.admin-template.name')) +@section(config('mail-tracker.admin-template.styles_section')) + +@endsection +@section(config('mail-tracker.admin-template.section')) +

Mail Tracker

+ New Mail +

+ All Sent Emails +
+ +

Url Clicked Detail for Email ID {{$details->first()->email->id}}

+
+ Recipient: {{$details->first()->email->recipient}}
+ Subject: {{$details->first()->email->subject}}
+ Sent At: {{$details->first()->email->created_at->format(config('mail-tracker.date-format'))}} +

+
+ + + + + + @foreach($details as $detail) + + + + + + + @endforeach +
UrlClicksFirst Click AtLast Click At
{{$detail->url}}{{$detail->clicks}}{{$detail->created_at->format(config('mail-tracker.date-format'))}}{{$detail->updated_at->format(config('mail-tracker.date-format'))}}
+
+@endsection From 00c8e6507a8138a0afe21d4f99ef7ffb87ce8c48 Mon Sep 17 00:00:00 2001 From: Maru Amallo-amamarul Date: Thu, 15 Sep 2016 07:34:33 -0300 Subject: [PATCH 06/11] README (vendor publish) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8027115..2494746 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ jdavidbakr\MailTracker\MailTrackerServiceProvider::class, Publish the config file and migration ``` bash -$ php artisan vendor:publish +$ php artisan vendor:publish --provider='jdavidbakr\MailTracker\MailTrackerServiceProvider' ``` Run the migration @@ -62,7 +62,7 @@ Once installed, all outgoing mail will be logged to the database. The following * **route**: The route information for the tracking URLs. Set the prefix and middlware as desired. * **admin-route**: The route information for the admin. Set the prefix and middleware. * **admin-template**: The params for the Admin Panel and Views. You can integrate your existing Admin Panel with the MailTracker admin panel. -* **date-format**: You can define the format to show dates in the Admin Panel. +* **date-format**: You can define the format to show dates in the Admin Panel. ## Events From e38c94490546282d692f5b9d6b3d907dd5982af8 Mon Sep 17 00:00:00 2001 From: Maru Amallo-amamarul Date: Thu, 15 Sep 2016 20:13:24 -0300 Subject: [PATCH 07/11] some details --- README.md | 4 +- config/mail-tracker.php | 6 +- src/views/show.blade.php | 120 ++++++++++++++++++++------------------- 3 files changed, 68 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 2494746..fb6c4d0 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,9 @@ When you do the php artisan vendor:publish simple views will add to your resourc ## Admin Panel -The standard admin panel route is located at /email-manager. +Config your admin-route in the config file. Set the prefix and middlware. +The route name is 'mailTracker_Index'. The standard admin panel route is located at /email-manager. +You can use route names to include them into your existing admin menu. You can customize your route in the config file. You can see all sent emails, total opens, total urls clicks, show individuals emails and show the urls clicked details. Also you can send emails from your admin panel. diff --git a/config/mail-tracker.php b/config/mail-tracker.php index e6beb77..9bb65f5 100644 --- a/config/mail-tracker.php +++ b/config/mail-tracker.php @@ -49,9 +49,9 @@ /** * Admin Tamplate * example - * 'name' => 'layouts.app' for Deafult emailTraking use 'emailTrakingViews::layouts.app' - * 'section' => 'content' for Deafult emailTraking use 'content' - * 'styles_section' => 'styles' for Deafult emailTraking use 'styles' + * 'name' => 'layouts.app' for Default emailTraking use 'emailTrakingViews::layouts.app' + * 'section' => 'content' for Default emailTraking use 'content' + * 'styles_section' => 'styles' for Default emailTraking use 'styles' */ 'admin-template' => [ 'name' => 'emailTrakingViews::layouts.app', diff --git a/src/views/show.blade.php b/src/views/show.blade.php index d998045..fe6136a 100644 --- a/src/views/show.blade.php +++ b/src/views/show.blade.php @@ -1,59 +1,64 @@ - - - - - Show Email - - - +@extends(config('mail-tracker.admin-template.name')) +@section(config('mail-tracker.admin-template.styles_section')) + +@endsection +@section(config('mail-tracker.admin-template.section'))

Mail Tracker



New Mail @@ -65,6 +70,5 @@ Subject: {{$email->subject}}
Sent At: {{$email->created_at->format(config('mail-tracker.date-format'))}}

- - +@endsection {!!$email->content!!} From 887843b35b0a7083c0881aab7a1cd6e98a28fa65 Mon Sep 17 00:00:00 2001 From: Jon Baker Date: Tue, 1 Nov 2016 15:44:57 -0500 Subject: [PATCH 08/11] Clicked URL tracking added to tests --- tests/MailTrackerTest.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/MailTrackerTest.php b/tests/MailTrackerTest.php index 2bef622..768aeba 100644 --- a/tests/MailTrackerTest.php +++ b/tests/MailTrackerTest.php @@ -4,22 +4,30 @@ class AddressVerificationTest extends TestCase { public function testSendMessage() { + $faker = Faker\Factory::create(); + $email = $faker->email; + $subject = $faker->sentence; + $name = $faker->firstName . ' ' .$faker->lastName; \View::addLocation(__DIR__); - \Mail::send('email.test', [], function ($message) { + \Mail::send('email.test', [], function ($message) use($email, $subject, $name) { $message->from('from@johndoe.com', 'From Name'); $message->sender('sender@johndoe.com', 'Sender Name'); - $message->to('to@johndoe.com', 'To Name'); + $message->to($email, $name); $message->cc('cc@johndoe.com', 'CC Name'); $message->bcc('bcc@johndoe.com', 'BCC Name'); $message->replyTo('reply-to@johndoe.com', 'Reply-To Name'); - $message->subject('Subject'); + $message->subject($subject); $message->priority(3); }); + $this->seeInDatabase('sent_emails',[ + 'recipient'=>$name.' <'.$email.'>', + 'subject'=>$subject, + ]); } public function testPing() @@ -49,7 +57,7 @@ public function testLink() $clicks = $track->clicks; $clicks++; - $redirect = 'http://mfn1.myfootballnow.com/community/thread/2/1636?page=4&x=tRnYCfp9mT#10111'; + $redirect = 'http://'.str_random(15).'.com/'.str_random(10).'/'.str_random(10).'/'.rand(0,100).'/'.rand(0,100).'?page='.rand(0,100).'&x='.str_random(32); $url = action('\jdavidbakr\MailTracker\MailTrackerController@getL',[ \jdavidbakr\MailTracker\MailTracker::hash_url($redirect), // Replace slash with dollar sign @@ -58,6 +66,11 @@ public function testLink() $this->call('GET',$url); $this->assertRedirectedTo($redirect); + $this->seeInDatabase('sent_emails_url_clicked',[ + 'url'=>$redirect, + 'clicks'=>1, + ]); + $track = $track->fresh(); $this->assertEquals($clicks, $track->clicks); From d4b28a2a7da39d0de8b86f2a32aeb268c20a852d Mon Sep 17 00:00:00 2001 From: Jon Baker Date: Tue, 1 Nov 2016 16:29:42 -0500 Subject: [PATCH 09/11] Wrapping admin pages in bootstrap, and removing the ability to create a new email from the admin --- README.md | 19 ++++- config/mail-tracker.php | 9 +- src/AdminController.php | 39 +-------- src/views/email_form.blade.php | 78 ------------------ src/views/index.blade.php | 141 +++++++++++--------------------- src/views/layouts/app.blade.php | 22 ++--- src/views/show.blade.php | 75 +---------------- src/views/url_detail.blade.php | 132 +++++++++++------------------- tests/MailTrackerTest.php | 4 +- 9 files changed, 133 insertions(+), 386 deletions(-) delete mode 100644 src/views/email_form.blade.php diff --git a/README.md b/README.md index fb6c4d0..cb2c16c 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,29 @@ MailTracker will hook into all outgoing emails from Laravel/Lumen and inject a tracking code into it. It will also store the rendered email in the database. There is also an interface to view sent emails. +## Upgrade from 1.x + +First, upgrade to version 2.0 by running: + +``` bash +$ composer require jdavidbakr/mail-tracker ~2.0 +``` + +Version 2.0 contains a new model that tracks the links that were clicked on. This requires a migration to create the table. Be sure to run + +``` bash +$ php artisan vendor:publish +$ php artisan migrate +``` + +after running composer update. + ## Install (Laravel) Via Composer ``` bash -$ composer require jdavidbakr/mail-tracker +$ composer require jdavidbakr/mail-tracker ~2.0 ``` Add the following to the providers array in config/app.php: diff --git a/config/mail-tracker.php b/config/mail-tracker.php index 9bb65f5..900309e 100644 --- a/config/mail-tracker.php +++ b/config/mail-tracker.php @@ -51,17 +51,20 @@ * example * 'name' => 'layouts.app' for Default emailTraking use 'emailTrakingViews::layouts.app' * 'section' => 'content' for Default emailTraking use 'content' - * 'styles_section' => 'styles' for Default emailTraking use 'styles' */ 'admin-template' => [ 'name' => 'emailTrakingViews::layouts.app', 'section' => 'content', - 'styles_section' => 'styles', ], + /** + * Number of emails per page in the admin view + */ + 'emails-per-page'=>30, + /** * Date Format */ - 'date-format' => 'd/m/Y', + 'date-format' => 'm/d/Y g:i a', ]; diff --git a/src/AdminController.php b/src/AdminController.php index 98e7481..4ded859 100644 --- a/src/AdminController.php +++ b/src/AdminController.php @@ -23,7 +23,7 @@ class AdminController extends Controller */ public function getIndex() { - $emails = SentEmail::all(); + $emails = SentEmail::paginate(config('mail-tracker.emails-per-page')); return \View('emailTrakingViews::index')->with('emails', $emails); } @@ -49,41 +49,4 @@ public function getUrlDetail($id) $detalle = SentEmailUrlClicked::where('sent_email_id',$id)->get(); return \View('emailTrakingViews::url_detail')->with('details', $detalle); } - - /** - * New Email. - * - * @return \Illuminate\Http\Response - */ - public function getNewEmail() - { - - return view('emailTrakingViews::email_form'); - } - - /** - * Send Email. - * - * @return \Illuminate\Http\Response - */ - public function getSendEmail(Request $request) - { - - $data = [ - 'name' => $request->name, - 'to' => $request->email, - 'message' => $request->message - ]; - Mail::send('emailTrakingViews::emails/mensaje', ['data' => $data], function($message) use ($data){ - $message->from(config('mail.from.address'), config('mail.from.name')); - $message->to($data['to'], $data['name']); - // $message->cc('cc@johndoe.com', 'CC Name'); - // $message->bcc('bcc@johndoe.com', 'BCC Name'); - // $message->replyTo('reply-to@johndoe.com', 'Reply-To Name'); - // $message->priority(3); - $message->subject('New Message from '. config('mail-tracker.name') ); - }); - \Log::notice('Email Sent to: '.$data['to'] . ' - '. $data['name']); - return redirect()->route('mailTracker_Index'); - } } diff --git a/src/views/email_form.blade.php b/src/views/email_form.blade.php deleted file mode 100644 index 73fbc3b..0000000 --- a/src/views/email_form.blade.php +++ /dev/null @@ -1,78 +0,0 @@ -@extends(config('mail-tracker.admin-template.name')) -@section('styles') - -@endsection -@section(config('mail-tracker.admin-template.section')) -

Mail Tracker

-
- All Sent Emails -
-
- New Mail -
-
-
- Name:
-
- Email:
-
- Message:
-

- -
-@endsection diff --git a/src/views/index.blade.php b/src/views/index.blade.php index 7549385..f5fb8ae 100644 --- a/src/views/index.blade.php +++ b/src/views/index.blade.php @@ -1,99 +1,52 @@ @extends(config('mail-tracker.admin-template.name')) -@section(config('mail-tracker.admin-template.styles_section')) - -@endsection @section(config('mail-tracker.admin-template.section')) -

Mail Tracker

-
- New Mail -

-
-
- - - - - - - - - - @foreach($emails as $email) - - - - - - - - - + + @endforeach +
RecipientSubjectOpensOpensClicksSend AtShow EmailUrl Report
{{$email->recipient}}{{$email->subject}}{{$email->opens > 0 ? 'OPENED' : 'NOT OPEN'}}{{$email->opens}}{{$email->clicks}}{{$email->created_at->format(config('mail-tracker.date-format'))}} - Show - - @if($email->clicks > 0) - Url Report +
+
+
+

Mail Tracker

+
+
+
+ +
+
+
+ + + + + + + + + + + @foreach($emails as $email) + + + + + + + + - - @endforeach -
RecipientSubjectOpensClicksSend AtView EmailClicks
{{$email->recipient}}{{$email->subject}}{{$email->opens}}{{$email->clicks}}{{$email->created_at->format(config('mail-tracker.date-format'))}} + View + + @if($email->clicks > 0) + Url Report @else - Not Clicks - @endif -
+ No Clicks + @endif +
+
+ +
+
+ {!! $emails->render() !!} +
+
@endsection diff --git a/src/views/layouts/app.blade.php b/src/views/layouts/app.blade.php index 8f21d51..9d55d24 100644 --- a/src/views/layouts/app.blade.php +++ b/src/views/layouts/app.blade.php @@ -1,11 +1,13 @@ - - - - Mail Tracker - @yield(config('mail-tracker.admin-template.styles_section')) - - - @yield('content') - - + + + + + + Mail Tracker + + + + @yield('content') + + \ No newline at end of file diff --git a/src/views/show.blade.php b/src/views/show.blade.php index fe6136a..9c4e553 100644 --- a/src/views/show.blade.php +++ b/src/views/show.blade.php @@ -1,74 +1 @@ -@extends(config('mail-tracker.admin-template.name')) -@section(config('mail-tracker.admin-template.styles_section')) - -@endsection -@section(config('mail-tracker.admin-template.section')) -

Mail Tracker

-

- New Mail -

- All Sent Emails -
-

Email ID {{$email->id}}

- Recipient: {{$email->recipient}}
- Subject: {{$email->subject}}
- Sent At: {{$email->created_at->format(config('mail-tracker.date-format'))}} -

-@endsection - {!!$email->content!!} +{!!$email->content!!} diff --git a/src/views/url_detail.blade.php b/src/views/url_detail.blade.php index 1e0fae3..3db225b 100644 --- a/src/views/url_detail.blade.php +++ b/src/views/url_detail.blade.php @@ -1,90 +1,50 @@ @extends(config('mail-tracker.admin-template.name')) -@section(config('mail-tracker.admin-template.styles_section')) - -@endsection @section(config('mail-tracker.admin-template.section')) -

Mail Tracker

- New Mail -

- All Sent Emails -
- -

Url Clicked Detail for Email ID {{$details->first()->email->id}}

-
- Recipient: {{$details->first()->email->recipient}}
- Subject: {{$details->first()->email->subject}}
- Sent At: {{$details->first()->email->created_at->format(config('mail-tracker.date-format'))}} -

-
- - - - - - @foreach($details as $detail) - - - - - - - @endforeach -
UrlClicksFirst Click AtLast Click At
{{$detail->url}}{{$detail->clicks}}{{$detail->created_at->format(config('mail-tracker.date-format'))}}{{$detail->updated_at->format(config('mail-tracker.date-format'))}}
+
+
+
+

Mail Tracker

+
+
+

+ All Sent Emails +

+
+
+
+
+

+ Clicked URLs for Email ID {{$details->first()->email->id}} +

+ + View Message + +
+
+
+
+ Recipient: {{$details->first()->email->recipient}}
+ Subject: {{$details->first()->email->subject}}
+ Sent At: {{$details->first()->email->created_at->format(config('mail-tracker.date-format'))}} +
+
+
+
+ + + + + + @foreach($details as $detail) + + + + + + + @endforeach +
UrlClicksFirst Click AtLast Click At
{{$detail->url}}{{$detail->clicks}}{{$detail->created_at->format(config('mail-tracker.date-format'))}}{{$detail->updated_at->format(config('mail-tracker.date-format'))}}
+
+
@endsection diff --git a/tests/MailTrackerTest.php b/tests/MailTrackerTest.php index 768aeba..4b1ae6d 100644 --- a/tests/MailTrackerTest.php +++ b/tests/MailTrackerTest.php @@ -66,6 +66,8 @@ public function testLink() $this->call('GET',$url); $this->assertRedirectedTo($redirect); + Event::assertFired(jdavidbakr\MailTracker\Events\LinkClickedEvent::class); + $this->seeInDatabase('sent_emails_url_clicked',[ 'url'=>$redirect, 'clicks'=>1, @@ -81,7 +83,5 @@ public function testLink() ]); $this->call('GET',$url); $this->assertRedirectedTo($redirect); - - Event::assertFired(jdavidbakr\MailTracker\Events\LinkClickedEvent::class); } } From 968dc7876b949a1e99c803657e45b3ebafea2a91 Mon Sep 17 00:00:00 2001 From: Jon Baker Date: Tue, 1 Nov 2016 16:58:50 -0500 Subject: [PATCH 10/11] Search function --- README.md | 9 ++--- config/mail-tracker.php | 59 ++++++++++++------------------ src/AdminController.php | 36 +++++++++++++++++- src/MailTrackerServiceProvider.php | 3 +- src/views/index.blade.php | 21 ++++++++++- src/views/url_detail.blade.php | 2 +- 6 files changed, 84 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index cb2c16c..f13e42d 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,13 @@ First, upgrade to version 2.0 by running: $ composer require jdavidbakr/mail-tracker ~2.0 ``` -Version 2.0 contains a new model that tracks the links that were clicked on. This requires a migration to create the table. Be sure to run +Version 2.0 contains a new model that tracks the links that were clicked on. This requires a migration to create the table. There are also additional changes to the config file. For best results, make a backup copy of config/mail-tracker.php to restore any values you have customized, then delete that file and run ``` bash $ php artisan vendor:publish $ php artisan migrate ``` -after running composer update. - ## Install (Laravel) Via Composer @@ -52,7 +50,7 @@ $ php artisan migrate Via Composer ``` bash -$ composer require jdavidbakr/mail-tracker +$ composer require jdavidbakr/mail-tracker ~2.0 ``` Register the following service provider in bootstrap/app.php @@ -147,8 +145,7 @@ The route name is 'mailTracker_Index'. The standard admin panel route is located You can use route names to include them into your existing admin menu. You can customize your route in the config file. You can see all sent emails, total opens, total urls clicks, show individuals emails and show the urls clicked details. -Also you can send emails from your admin panel. -All views (email tamplates, panel) can customize in resources/views/vendor/emailTrakingViews. +All views (email tamplates, panel) can be customized in resources/views/vendor/emailTrakingViews. ## Contributing diff --git a/config/mail-tracker.php b/config/mail-tracker.php index 900309e..aa234f9 100644 --- a/config/mail-tracker.php +++ b/config/mail-tracker.php @@ -1,41 +1,27 @@ - 'Mail Tracker', - - /** - * To disable the pixel injection, set this to false. - */ - 'inject-pixel'=>true, + /** + * To disable the pixel injection, set this to false. + */ + 'inject-pixel'=>true, - /** - * To disable injecting tracking links, set this to false. - */ - 'track-links'=>true, + /** + * To disable injecting tracking links, set this to false. + */ + 'track-links'=>true, - /** - * Optionally expire old emails, set to 0 to keep forever. - */ - 'expire-days'=>60, + /** + * Optionally expire old emails, set to 0 to keep forever. + */ + 'expire-days'=>60, - /** - * Where should the pingback URL route be? - */ + /** + * Where should the pingback URL route be? + */ 'route' => [ 'prefix' => 'email', - 'middleware' => [], + 'middleware' => ['web'], ], /** @@ -43,14 +29,15 @@ */ 'admin-route' => [ 'prefix' => 'email-manager', - 'middleware' => 'super', + 'middleware' => ['web'], ], /** * Admin Tamplate - * example - * 'name' => 'layouts.app' for Default emailTraking use 'emailTrakingViews::layouts.app' - * 'section' => 'content' for Default emailTraking use 'content' + * example + * 'name' => 'layouts.app' for Default emailTraking use 'emailTrakingViews::layouts.app' + * 'section' => 'content' for Default emailTraking use 'content' + * 'styles_section' => 'styles' for Default emailTraking use 'styles' */ 'admin-template' => [ 'name' => 'emailTrakingViews::layouts.app', @@ -60,7 +47,7 @@ /** * Number of emails per page in the admin view */ - 'emails-per-page'=>30, + 'emails-per-page'=>5, /** * Date Format diff --git a/src/AdminController.php b/src/AdminController.php index 4ded859..bfae571 100644 --- a/src/AdminController.php +++ b/src/AdminController.php @@ -16,6 +16,24 @@ class AdminController extends Controller { + /** + * Sent email search + */ + public function postSearch(Request $request) + { + session(['mail-tracker-index-search'=>$request->search]); + return redirect(route('mailTracker_Index')); + } + + /** + * Clear search + */ + public function clearSearch() + { + session(['mail-tracker-index-search'=>null]); + return redirect(route('mailTracker_Index')); + } + /** * Index. * @@ -23,7 +41,23 @@ class AdminController extends Controller */ public function getIndex() { - $emails = SentEmail::paginate(config('mail-tracker.emails-per-page')); + session(['mail-tracker-index-page'=>request()->page]); + $search = session('mail-tracker-index-search'); + + $query = SentEmail::query(); + + if($search) { + $terms = explode(" ",$search); + foreach($terms as $term) { + $query->where(function($q) use($term) { + $q->where('sender','like','%'.$term.'%') + ->orWhere('recipient','like','%'.$term.'%') + ->orWhere('subject','like','%'.$term.'%'); + }); + } + } + + $emails = $query->paginate(config('mail-tracker.emails-per-page')); return \View('emailTrakingViews::index')->with('emails', $emails); } diff --git a/src/MailTrackerServiceProvider.php b/src/MailTrackerServiceProvider.php index a668483..62d30db 100644 --- a/src/MailTrackerServiceProvider.php +++ b/src/MailTrackerServiceProvider.php @@ -70,9 +70,10 @@ public function boot() Route::group($config_admin, function() { Route::get('/', 'AdminController@getIndex')->name('mailTracker_Index'); + Route::post('search', 'AdminController@postSearch')->name('mailTracker_Search'); + Route::get('clear-search', 'AdminController@clearSearch')->name('mailTracker_ClearSearch'); Route::get('show-email/{id}', 'AdminController@getShowEmail')->name('mailTracker_ShowEmail'); Route::get('url-detail/{id}', 'AdminController@getUrlDetail')->name('mailTracker_UrlDetail'); - Route::get('new-email', 'AdminController@getNewEmail')->name('mailTracker_NewEmail'); Route::get('send-email', 'AdminController@getSendEmail')->name('mailTracker_SendEmail'); }); } else { diff --git a/src/views/index.blade.php b/src/views/index.blade.php index f5fb8ae..db11c62 100644 --- a/src/views/index.blade.php +++ b/src/views/index.blade.php @@ -7,7 +7,26 @@
- +
+
+ {!! csrf_field() !!} +
+ + +
+ + +
+
+
diff --git a/src/views/url_detail.blade.php b/src/views/url_detail.blade.php index 3db225b..45e3449 100644 --- a/src/views/url_detail.blade.php +++ b/src/views/url_detail.blade.php @@ -7,7 +7,7 @@
From 9d9e0e9d5b120db8d28678cb1267bb884a2f0521 Mon Sep 17 00:00:00 2001 From: Jon Baker Date: Tue, 1 Nov 2016 17:04:13 -0500 Subject: [PATCH 11/11] (hopefully) working lumen version of the admin routes --- src/MailTrackerServiceProvider.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/MailTrackerServiceProvider.php b/src/MailTrackerServiceProvider.php index 62d30db..8dc006d 100644 --- a/src/MailTrackerServiceProvider.php +++ b/src/MailTrackerServiceProvider.php @@ -58,8 +58,8 @@ public function boot() } else { $app = $this->app; $app->group($config, function () use ($app) { - $app->get('t', 'MailTrackerController@getT'); - $app->get('l', 'MailTrackerController@getL'); + $app->get('t', 'MailTrackerController@getT')->name('mailTracker_t'); + $app->get('l', 'MailTrackerController@getL')->name('mailTracker_l'); }); } // Install the Admin routes @@ -79,9 +79,12 @@ public function boot() } else { $app = $this->app; $app->group($config_admin, function () use ($app) { - $app->get('index', 'AdminController@getIndex'); - $app->get('example-email', 'AdminController@getExampleEmail'); - $app->get('url-detail', 'AdminController@getUrlDetail'); + $app->get('/', 'AdminController@getIndex')->name('mailTracker_Index'); + $app->post('search', 'AdminController@postSearch')->name('mailTracker_Search'); + $app->get('clear-search', 'AdminController@clearSearch')->name('mailTracker_ClearSearch'); + $app->get('show-email/{id}', 'AdminController@getShowEmail')->name('mailTracker_ShowEmail'); + $app->get('url-detail/{id}', 'AdminController@getUrlDetail')->name('mailTracker_UrlDetail'); + $app->get('send-email', 'AdminController@getSendEmail')->name('mailTracker_SendEmail'); }); } }