Download the PHP package webiny/analytics-db without Composer
On this page you can find all versions of the php package webiny/analytics-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webiny/analytics-db
More information about webiny/analytics-db
Files in webiny/analytics-db
Package analytics-db
Short Description Library to help you with storing different time series analytics data.
License MIT
Homepage http://www.webiny.com/
Informations about the package analytics-db
AnalyticsDb
AnalyticsDb is a component that enables you to store and query different time-series (numerical) data. Simple use-case would be tracking the number of visitors for your website inside the given date/time range, or tracking ecommerce revenue for a given quarter.
Dependencies
The component requires an instance of \Webiny\Component\Mongo\Mongo
to access your Mongo database where it will create
several collections to store the data.
Dimensions
Dimensions track different data which is still tied to your entity. For example say you have a product A, in 2 colors, red and blue. The product would be your entity, and colors would be your dimensions.
When tracking the dimensions, you can then get stats like "show me the views on all red
version of my product".
Attributes
Attributes are much simpler than dimensions. Attributes are just additional tags you can attach to an entity so you can group, sort and filter by them. A typical use-case for attributes is say you have a product, which has a certain brand and you want to be able to get a list of top 10 products for a certain brand.
You can add multiple attributes to a product.
Now you can do something like this:
Storing data
The data is stored using the log
method. Note that data is not actually saved until you call the save
method.
To assign attributes to your data, for example you wish to increment the number of visitors on your site, but you also want
to store some attributes, like what browser the user used, and from which country he came from; for that you can use dimensions
.
Dimensions are also counters which can be queried.
For example, for this use case:
You can know how many visitors you had for a given date range, and you can group that result either by day, or by month.
Since you stored some data in dimensions, you can also know, how many users used chrome
vs, for example firefox
or ie
,
and then you can cross reference that to the total number of your visitors.
You can also assign a referral value to the log, for example, you can track per-page analytics like so:
This will track a visitor for page with the id of 123. And then later you can query the analytics data for that page.
Some best practice is not to query data with a large set of different referrals. For example if you want to know how many visitors in total you had on your website, don't query and then sum the number of visitors of all your pages. Instead store 2 different analytics data, one for pages, and one for visitors in general.
By default the log
method will increment the value by 1, but in some cases, for example when you wish to track revenue,
you want to specify the increment value, and this is done by using the 3rd parameter, like so:
This will increase the revenue
counter by 120.00
(float value is supported).
Querying data
To query the data, you need to get an instance of the query
, like so:
For the query
you have to specify the entity name, referral, and the date range.
There is a DateHelper
class to help you in regards to some commonly used date ranges, but you can also specify your own custom range,
it is just an array with two unix timestamps [dateFromTimestamp, dateToTimestamp]
.
Once you have the query
instance, you can get the results for the given range. By default the data is grouped by day, but you
can also get it in a per-month format.
To query dimensions, use the dimension
method, like so:
License and Contributions
Contributing > Feel free to send PRs.
License > MIT
Resources
To run unit tests, you need to use the following command: