Add Analytics integration with MixPanel
This commit is contained in:
8
assets/js/lib/analytics.js
Normal file
8
assets/js/lib/analytics.js
Normal file
@ -0,0 +1,8 @@
|
||||
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
||||
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
|
||||
|
||||
mixpanel.init("f683d388fb25fcf331f1b2b5c4449798");
|
||||
|
||||
if (typeof mailpoet_analytics_data === 'object') {
|
||||
mixpanel.track('Wysija Usage', mailpoet_analytics_data || {});
|
||||
}
|
25
lib/Analytics/Reporter.php
Normal file
25
lib/Analytics/Reporter.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace MailPoet\Analytics;
|
||||
|
||||
class Reporter {
|
||||
|
||||
private $fields = array(
|
||||
'Plugin Version' => 'pluginVersion',
|
||||
);
|
||||
|
||||
function __construct() {}
|
||||
|
||||
function getData() {
|
||||
$_this = $this;
|
||||
|
||||
$analytics_data = array_map(function($func) use ($_this) {
|
||||
return $_this->$func();
|
||||
}, $this->fields);
|
||||
|
||||
return $analytics_data;
|
||||
}
|
||||
|
||||
private function pluginVersion() {
|
||||
return MAILPOET_VERSION;
|
||||
}
|
||||
}
|
32
lib/Config/Analytics.php
Normal file
32
lib/Config/Analytics.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace MailPoet\Config;
|
||||
use \MailPoet\Analytics\Reporter;
|
||||
use \MailPoet\Models\Setting;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Analytics {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function init() {
|
||||
add_action('admin_enqueue_scripts', array($this, 'setupAdminDependencies'));
|
||||
}
|
||||
|
||||
function setupAdminDependencies() {
|
||||
if(Setting::getValue('send_analytics_now', false)) {
|
||||
$analytics = new Reporter();
|
||||
wp_enqueue_script(
|
||||
'analytics',
|
||||
Env::$assets_url . '/js/lib/analytics.js',
|
||||
array(),
|
||||
Env::$version
|
||||
);
|
||||
wp_localize_script(
|
||||
'analytics',
|
||||
'mailpoet_analytics_data',
|
||||
$analytics->getData()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ class Initializer {
|
||||
$this->setupMenu();
|
||||
$this->setupRouter();
|
||||
$this->setupWidget();
|
||||
$this->setupAnalytics();
|
||||
$this->setupPermissions();
|
||||
}
|
||||
|
||||
@ -94,6 +95,11 @@ class Initializer {
|
||||
$widget->init();
|
||||
}
|
||||
|
||||
function setupAnalytics() {
|
||||
$widget = new Analytics();
|
||||
$widget->init();
|
||||
}
|
||||
|
||||
function setupPermissions() {
|
||||
$permissions = new Permissions();
|
||||
$permissions->init();
|
||||
|
Reference in New Issue
Block a user