diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 165f54ef9ed0..035faee4827d 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -477,6 +477,7 @@ class PaymentController extends BaseController if ($account->account_key == NINJA_ACCOUNT_KEY) { Session::flash('trackEventCategory', '/account'); Session::flash('trackEventAction', '/buy_pro_plan'); + Session::flash('trackEventAmount', $payment->amount); } return Redirect::to('view/'.$payment->invitation->invitation_key); diff --git a/app/Http/routes.php b/app/Http/routes.php index c1162db275c1..c379becaad3d 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -572,6 +572,7 @@ if (!defined('CONTACT_EMAIL')) { define('REFERRAL_PROGRAM_URL', env('REFERRAL_PROGRAM_URL', 'https://www.invoiceninja.com/referral-program/')); define('EMAIL_MARKUP_URL', env('EMAIL_MARKUP_URL', 'https://developers.google.com/gmail/markup')); define('OFX_HOME_URL', env('OFX_HOME_URL', 'http://www.ofxhome.com/index.php/home/directory/all')); + define('GOOGLE_ANALYITCS_URL', env('GOOGLE_ANALYITCS_URL', 'https://www.google-analytics.com/collect')); define('BLANK_IMAGE', 'data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='); @@ -585,7 +586,6 @@ if (!defined('CONTACT_EMAIL')) { define('INVOICE_DESIGNS_AFFILIATE_KEY', 'T3RS74'); define('SELF_HOST_AFFILIATE_KEY', '8S69AD'); - define('PRO_PLAN_PRICE', env('PRO_PLAN_PRICE', 50)); define('PLAN_PRICE_PRO_MONTHLY', env('PLAN_PRICE_PRO_MONTHLY', 5)); define('PLAN_PRICE_PRO_YEARLY', env('PLAN_PRICE_PRO_YEARLY', 50)); define('PLAN_PRICE_ENTERPRISE_MONTHLY', env('PLAN_PRICE_ENTERPRISE_MONTHLY', 10)); diff --git a/app/Listeners/AnalyticsListener.php b/app/Listeners/AnalyticsListener.php new file mode 100644 index 000000000000..92c81205ab79 --- /dev/null +++ b/app/Listeners/AnalyticsListener.php @@ -0,0 +1,54 @@ +payment; + $invoice = $payment->invoice; + $account = $payment->account; + + if ($account->account_key != NINJA_ACCOUNT_KEY) { + return; + } + + $analyticsId = env('ANALYTICS_KEY'); + $client = $payment->client; + $amount = $payment->amount; + + $base = "v=1&tid={$analyticsId}&cid{$client->public_id}&cu=USD&ti={$invoice->invoice_number}"; + + $url = $base . "&t=transaction&ta=ninja&tr={$amount}"; + $this->sendAnalytics($url); + //Log::info($url); + + $url = $base . "&t=item&in=plan&ip={$amount}&iq=1"; + $this->sendAnalytics($url); + //Log::info($url); + } + + private function sendAnalytics($data) + { + $data = json_encode($data); + $curl = curl_init(); + + $opts = [ + CURLOPT_URL => GOOGLE_ANALYITCS_URL, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => 'POST', + CURLOPT_POSTFIELDS => $data, + ]; + + curl_setopt_array($curl, $opts); + $response = curl_exec($curl); + curl_close($curl); + } +} diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index cd08e33a855d..5c006ecd9eaa 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -799,7 +799,6 @@ class Invoice extends EntityModel implements BalanceAffecting $invitation = $this->invitations[0]; $link = $invitation->getLink('view', true); $key = env('PHANTOMJS_CLOUD_KEY'); - $curl = curl_init(); if (Utils::isNinjaDev()) { $link = env('TEST_LINK'); diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index bb4e94d79546..45c4a789ca22 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -98,6 +98,7 @@ class EventServiceProvider extends ServiceProvider { 'App\Listeners\SubscriptionListener@createdPayment', 'App\Listeners\InvoiceListener@createdPayment', 'App\Listeners\NotificationListener@createdPayment', + 'App\Listeners\AnalyticsListener@trackRevenue', ], 'App\Events\PaymentWasArchived' => [ 'App\Listeners\ActivityListener@archivedPayment', diff --git a/resources/views/master.blade.php b/resources/views/master.blade.php index 0cdb55ea5573..b0d59cc90254 100644 --- a/resources/views/master.blade.php +++ b/resources/views/master.blade.php @@ -177,9 +177,8 @@ }); @if (Session::has('trackEventCategory') && Session::has('trackEventAction')) - trackEvent('{{ session('trackEventCategory') }}', '{{ session('trackEventAction') }}'); @if (Session::get('trackEventAction') === '/buy_pro_plan') - window._fbq.push(['track', '{{ env('FACEBOOK_PIXEL_BUY_PRO') }}', {'value':'{{ PRO_PLAN_PRICE }}.00','currency':'USD'}]); + window._fbq.push(['track', '{{ env('FACEBOOK_PIXEL_BUY_PRO') }}', {'value':'{{ session('trackEventAmount') }}','currency':'USD'}]); @endif @endif