1. Go to this page and download the library: Download altis/aws-analytics library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
altis / aws-analytics example snippets
$result = Altis\Analytics\Utils\query( [
// Don't return any hits to keep the response size small.
'size' => 0,
// Restrict the results to a single page we're interested in.
'query' => [
'bool' => [
'filter' => [
[ 'term' => [ 'attributes.url.keyword' => 'https://example.com/page' ] ]
]
]
],
// Aggregate data sets
'aggs' => [
'sessions' => [
// Create buckets by page session ID so all records in each bucket belong
// to a single user and page session.
'terms' => [
'field' => 'attributes.pageSession.keyword',
// Use data from the top 100 unique page sessions.
// By default terms aggregations return the top 10 hits.
'size' => 100
],
// Sub aggregations.
'aggs' => [
// Get the time on page by summing all session.duration values for the page session.
'time_on_page' => [
'sum' => [ 'field' => 'session.duration' ]
]
]
],
// Create a stats aggregation for all the time on page values found above.
'stats' => [
'stats_bucket' => [
'buckets_path' => 'sessions>time_in_page'
]
]
],
// Order by latest events.
'order' => [ 'event_timestamp' => 'desc' ]
] );
use function Altis\Analytics\Audiences\register_field;
add_action( 'init', function () {
register_field(
'endpoint.Location.Country', // The Elasticsearch field to query.
__( 'Country' ), // A label for the field.
__( 'The visitor country.' ) // Optional description for the field.
[ // Optional field arguments
'options' => '\\Altis\\Analytics\\Utils\\get_countries', // A callback to provide prepopulated list of options.
'disable_free_text' => false, // Whether to allow free text to be used or to restrict to available options.
]
);
} );