Skip to content
Products
Apps
Docs
Log in
Log in
Sign up
Sign up
Products
Apps
Docs
Docs
Docs
CODE
On this page

Analytics for developers

Send custom events with bx_analytics.track on the classic site, trackEvent in NEO or the track service in PHP, post hits from any client to the collect service, read any report as JSON with get_report, and add your module's own revenue figures with a get_analytics_revenue service.
Android
iOS
Web
Core
Client
~15.0
Source
Copy Page
Note
window.bx_analytics && bx_analytics.track('signup_click', {plan: 'pro'});
import { trackEvent } from 'app/lib/analytics';

trackEvent('signup_click', { plan: 'pro' });
bx_srv('bx_analytics', 'track', ['export_done', ['rows' => 120]]);
Note
curl -X POST 'https://example.com/api.php?r=bx_analytics/collect' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"platform": "api", "app": "my-client", "app_version": "1.0.0", "hits": [{"type": "pageview", "url": "https://example.com/pricing", "title": "Pricing"}, {"type": "event", "name": "signup_click", "url": "https://example.com/pricing", "props": {"plan": "pro"}}]}'
api.php?r=bx_analytics/get_tracker_config&params[]=next-web
bx_srv('bx_analytics', 'get_report', ['overview', ['range' => '30d', 'platform' => 'rn-ios']]);
api.php?r=bx_analytics/get_report&params[]=top&params[]={"group":"pages","tab":"entry","range":"7d"}
public function serviceGetAnalyticsRevenue($aParams = [])
{
    $aResult = ['title' => '_bx_mymodule', 'unit' => 'money'];
    if(!is_array($aParams) || !empty($aParams['meta']))
        return $aResult;

    // count what happened between $aParams['from'] and $aParams['to'] (unix times, `to` exclusive)
    $aResult['metrics'] = [
        'issued' => ['title' => '_bx_mymodule_txt_analytics_issued', 'value' => 12, 'money' => 480.0],
    ];

    return $aResult;
}
docker compose exec -w /opt/una php ./plugins/bin/phpunit -c tests/phpunit.xml --filter 'Analytics|BxAnalytics'
21d
On this page
I want toPlatformsHits from trackersSite actions and server eventsCustom eventsNames and propertiesThe collect endpointPayloadTracker settingsWhat the collector dropsReading reportsFilter parametersEach report's own parametersExplore > APIBlock servicesNEOElementsTrackerfetcherRevenue from your moduleSales through PaymentsYour own figures: getanalyticsrevenueContent report hooksDataReport cacheTestsTipsTroubleshootingSourcesRelated
Introduction
Getting Started
Configuration
Apps
CODE
Developer Architecture
Code Convention
Code Quality
Directory Structure
How to Add an App
Storage System
Common Mistakes
Payment Provider Integration
Module API
iOS Client
NEO Developer
Android Client
Web Client
Contributing
REST API
Analytics Developer
Auth
Connect
curl -X POST 'https://example.com/api.php?r=bx_analytics/collect' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"platform": "api", "app": "my-client", "app_version": "1.0.0", "hits": [{"type": "pageview", "url": "https://example.com/pricing", "title": "Pricing"}, {"type": "event", "name": "signup_click", "url": "https://example.com/pricing", "props": {"plan": "pro"}}]}'
public function serviceGetAnalyticsRevenue($aParams = [])
{
    $aResult = ['title' => '_bx_mymodule', 'unit' => 'money'];
    if(!is_array($aParams) || !empty($aParams['meta']))
        return $aResult;

    // count what happened between $aParams['from'] and $aParams['to'] (unix times, `to` exclusive)
    $aResult['metrics'] = [
        'issued' => ['title' => '_bx_mymodule_txt_analytics_issued', 'value' => 12, 'money' => 480.0],
    ];

    return $aResult;
}