Skip to content
Products
Docs
Pricing
Blog
Log In
Sign Up
Docs
Docs
CODE
On this page

Analytics for developers

Send custom events from the site, NEO and PHP, read any report as JSON, and add a module's revenue to Analytics.
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'
9d
On this page
PlatformsHits 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 cacheTests
Auto
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;
}