-
Notifications
You must be signed in to change notification settings - Fork 0
Operations
Metrics in Laika are obtained through one of three types of operations:
- Values fetched from an external data souce (like Google Analytics)
- The result of calculations on other metrics values
- Manually entered values
Laika comes with built-in support to fetch data directly from Google Analytics.
It's very straightforward to fetch data from individual measurements in a Google Analytics profile.
Need to understand the GAPI calls language.
Obtaining data for goals is slightly more complex, but still possible through built-in functions in Laika.
Since Google Analytics limits the number of goals that can exist in a given property, goals data can sometimes be spread out over several analytics properties. To help with this situation, Laika supports fetching goal data from different properties with a flexible goal-fetching data structure.
Consider the following goal-fetching item in the metrics table:
| id | name | is_global | operation |
|---|---|---|---|
| 43 | Goal: View product page | 0 | fetchGoalData(); |
In order to fetch data for a goal, the metrics table operation field simply needs to be:
fetchGoalData();
Despite the function not having any parameters, Laika will use its position in the iteration of sites and metrics to determine which values to return. The data for goals is stored in the goals table:
| id | report_item | site | gan_profile | gan_goal_id |
|---|---|---|---|---|
| 1 | 43 | 1 | 211731 | 4 |
| 2 | 43 | 2 | 211731 | 5 |
| 3 | 43 | 3 | 165697 | 8 |
During the fetch procedure, when Laika reaches metric 43, fetchGoalData() instructs Laika to query the goals table and look up the corresponding report_item and site that is being iterated. From there, Laika knows which Google Analytics profile to get data from, and which Goal ID within that profile contains the value being sought after.
Simply create a record in the goals table for each combination of metric and site, and then supply the appropriate gan_profile and goal_id so Laika knows where to collect the data from.
- To find the
goal_id, look up the goals for the Google Analytics view, and then find the "Goal ID" in the list.
Once data exists in the database, Laika can perform operations on it.
In this example, we will calculate the ratio of a certain value and find its remainder value to create a ratio chart of mobile and non-mobile site visits.
Consider the following items in the metrics table:
| id | name | is_global | operation |
|---|---|---|---|
| 1 | Total site visits | 1 | fetchData('getSessions','country','sessions'); |
| 12 | Mobile site visits | 1 | fetchData('getSessions','country','sessions','deviceCategory == mobile'); |
With those existing metrics, the ratio of mobile and non-mobile visits can be calculated by creating two new items in the metrics table:
| id | name | is_global | operation |
|---|---|---|---|
| 15 | Device: Mobile (ratio) | 1 | getValue(12)/getValue(1); |
| 16 | Device: Non-mobile (ratio) | 1 | 1-getValue(15); |
- Laika does not perform any calculations on-the-fly during the dashboard viewing process, so all desired metrics must be generated during the fetching process.
If an operation value is not provided for a given metric, no data fetch or calculation operation will be performed.
Data points can then be manually added to the data table using the id value of that particular manual metric, and then dashboards can be created to show that data.
This allows reporting on ad-hoc or other non-fetchable data using Laika's standard dashboard charting system.