Skip to content
This repository was archived by the owner on Nov 2, 2022. It is now read-only.

Operations

Gaelan Lloyd edited this page Sep 2, 2016 · 3 revisions

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

Fetched values

Laika comes with built-in support to fetch data directly from Google Analytics.

Direct value fetching

To fetch data from a Google Analytics profile, use fetchData() and pass the GAPI filter control language for your query.

  • There are many more metrics that can be retrieved from Google Analytics. Take a look at Google's Dimensions & Metrics Explorer to view more possibilities.
  • You can optionally wrap a fetch call with dePercent() to divide the result by 100, writing a decimal ratio to the database instead of a percent.

Examples

Measurement to fetch Operation to enter into database
Total sessions fetchData('getSessions','country','sessions');
Percent new sessions (represented as a decimal ratio like 0.25) dePercent(fetchData('getPercentNewSessions','country','percentNewSessions'));
Average session duration fetchData('getAvgSessionDuration','country','avgSessionDuration');
Average page views per session fetchData('getPageviewsPerSession','country','pageviewsPerSession');
Referral traffic fetchData('getSessions','country','sessions','channelGrouping == Referral');
Organic search traffic fetchData('getSessions','country','sessions','channelGrouping == Organic Search');
Direct traffic fetchData('getSessions','country','sessions','channelGrouping == Direct');
Paid search traffic fetchData('getSessions','country','sessions','channelGrouping == Paid Search');
Social media traffic fetchData('getSessions','country','sessions','channelGrouping == Social');
Mobile device traffic fetchData('getSessions','country','sessions','deviceCategory == mobile');
Tablet device traffic fetchData('getSessions','country','sessions','deviceCategory == tablet');
Desktop traffic fetchData('getSessions','country','sessions','deviceCategory == desktop');
Bounce rate (represented as a decimal ratio like 0.25) dePercent(fetchData('getBounceRate','country','bounceRate'));
Decimal ratio of referral bounce traffic dePercent(fetchData('getBounceRate','country','bounceRate','channelGrouping == Referral'));
Decimal ratio of organic search traffic dePercent(fetchData('getBounceRate','country','bounceRate','channelGrouping == Organic Search'));
Get visits from United States fetchDataCountryVisits('United States');
Get visits from United Kingdom fetchDataCountryVisits('United Kingdom');
Get visits from Germany fetchDataCountryVisits('Germany');

Goal value fetching

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.

Calculated values

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.

Manually entered values

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.

Clone this wiki locally