public function getWidget() { $api = new Api(API_PROJECT, API_READ_KEY); $qb = $api->getQueryBuilder(); $data = $qb->type('count')->collection('update')->filters([$qb->getFilterExpression('action', 'expand')])->groupBy('label')->timezone('UTC')->timeframe('this_2_days')->sort(Result::SORT_DESC)->limit(5)->execute()->toArray(); return (new GraphJsonFormatter())->setTitle('Most Expanded Updates in the last 2 days')->setData($this->trimTitles($data))->toJson(); }
public function getWidget() { $api = new Api(API_PROJECT, API_READ_KEY); $qb = $api->getQueryBuilder(); $data = $qb->type('count')->collection('update')->filters([$qb->getFilterExpression('action', 'expand')])->timezone('UTC')->timeframe('this_24_hours')->interval('hourly')->execute()->toArray(); return (new GraphJsonFormatter())->setTitle('Update Expands over the last 24 hours')->setData($data)->toJson(); }
public function getWidget() { $api = new Api(API_PROJECT, API_READ_KEY); $qb = $api->getQueryBuilder(); $data = $qb->type('count_unique')->collection('Loaded%20a%20Page')->targetProperty('user.userId')->timezone('UTC')->timeframe('this_15_minutes')->execute()->toArray(); $html = (new DiyHtmlFormatter())->setName('Active Users')->setRefresh(60)->setData($data); return $html->setTemplate('diy-active-users')->toHtml(); }
public function getWidget() { $api = new Api(API_PROJECT, API_READ_KEY); $qb = $api->getQueryBuilder(); $data = $qb->type('count_unique')->collection('Loaded%20a%20Page')->targetProperty('user.userId')->filters([$qb->getFilterExpression('ip_geo_info.continent', 'Europe')])->groupBy('ip_geo_info.country')->timezone('UTC')->timeframe('this_7_days')->execute()->toArray(); $html = (new DiyHtmlFormatter())->setName('User Geo Map')->setDefaultSize(7, 4)->setData($data); return $html->setTemplate('diy-user-geo-map')->toHtml(); }
define('API_PROJECT', $_SERVER['KEENIO_API_PROJECT']); $AVAILABLE_PARAMS = ['type', 'collection', 'group_by', 'timezone', 'timeframe', 'filter', 'interval', 'sort', 'limit']; // widgets if (preg_match('/\\/widgets\\/([a-zA-Z0-9]*)(.*)?/i', @$_SERVER['REDIRECT_URL'], $matches)) { @(list($url, $widgetName, $params) = $matches); if (!empty($widgetName) && WidgetLoader::exists($widgetName)) { $widget = WidgetLoader::load($widgetName, $params); die($widget->getWidget()); } else { die('Widget "' . $widgetName . '" not installed/available'); } } elseif (preg_match('/\\/explorer(\\/([a-zA-Z_]*))?/i', @$_SERVER['REDIRECT_URL'], $matches)) { if (@$matches[2]) { $_GET['type'] = $matches[2]; } $api = new Api(API_PROJECT, API_READ_KEY); $qb = $api->getQueryBuilder(); // parse request and map to query builder foreach ($_GET as $name => $value) { if (in_array(strtolower($name), $AVAILABLE_PARAMS)) { $param = underscoreToCamelCase(strtolower($name)); $qb->{$param}($value); } } $data = $qb->execute()->toArray(); die(json_encode($data, JSON_PRETTY_PRINT)); } die('you either need to load a widget (/widget/{WIDGET_NAME}) or use the explorer (/explorer/{PARAMS})'); function underscoreToCamelCase($string) { $func = create_function('$c', 'return strtoupper($c[1]);');