In this tutorial, we will use Rules in order to query for usage data related to page views and then pivot the data to aggregate it either by week or by month. This will be accomplished by creating a Dataset Task that queries the usage data within the MDA, and then creating a separate Dataset Task that pivots the data and completes the aggregation.
Following are the goals we intend to achieve using a single rule:
- Create Dataset to Fetch Data from MDA.
- Create Dataset to Pivot on Pages data.
Fetch Data from MDA
- In this step, Navigate to Administration > Rules Engine and create a Rule that enables you to fetch data from MDA.
- Enter following details in the Create Rule page:
- Rule For: Select Company.
- Rule Name: Enter an appropriate name.
- Folder: Select a folder for the rule.
- Description: Enter description (optional).
- Click NEXT. Setup Rule page appears.
- In the Setup Rule, click DATASET in order to begin creating the tasks the rules will need to complete.
- Set a Task Name and an Output Dataset Name for your Dataset Task. The Task Name will be used to identify the task within the rule, while the Output.
Dataset Name will be used to identify the resulting dataset after the task is completed. Gainsight recommends adding a Task Description with more details about the dataset.
In our example, this task will fetch data from the MDA and then pivot on the Page Name; so we have named the task, its description, and its output dataset name, accordingly.
- Click SAVE.
Since the goal of this rule is to fetch data from the MDA, select the object that you previously uploaded your Usage Data into.
Add the fields that you would like to reference as part of the pivot and the aggregation and add them to the Show section. In our example, we’ve selected the example object Usage Data. In the Show section, we’ve added the fields Company and Company Name (in order to tie this data back to those records). We’ve also added Date Field, Page Name, and Views as those will be necessary fields for the Pivot and Aggregation.
Note: While not necessary to complete this tutorial, each Dataset Task also has a section for exporting the resulting data to the S3. For more information on the options presented, click here. Select the exporting option that works best for your team.
- Click SAVE in the top-right to save the task.
Pivot on Pages Data
- Go back to the Setup Rule and click +TASK in order to add a new Dataset Task and Select Pivot to complete pivot and aggregate the usage data.
- Enter the Task Name, Task Description, and Output Dataset Name for this task. Following example shows the Task Name and Output Dataset Name as this task is to pivot on page data and aggregate by date.
- Under Dataset, select Fetch from MDA in order to pull in the data fetched by the previous task. Also add the fields Date Field and Company into the Show section, to give reference that data within the task.
- Drag the Page Name field and drop it under the Pivot On section. The Pivot conditions to evaluate window is displayed.
- Configure the conditions as shown below:
- Values of the Page Name
- Use the Output Field Label column to determine how the pivoted data will be identified,
- Aggregation column to determine how the data will be aggregated.
- Field column to determine what data will be selected as part of the pivot.
- Default Value column to determine value of data that is fetched, but does not meet the pivot condition. Set this to 0, to avoid views from other pages to throw off our aggregations.
- In the following example, various aggregation methods are used on three pages:
Click +ADD to add additional rows.
Click OK to set the conditions.
In the GroupBy section, add Date Field and Company Name to ensure the aggregation successfully groups the data by time for each company. When you drag the Date field to Group By section, Company Name field automatically changes to Count of Company , in the Show section. You must change this aggregation and then drag and drop the Company Name field to GroupBy section.
Click the gear icon on the Date Field in order to select how frequently you would like the aggregation to be grouped by. For weekly aggregation, select First Day of Current Week or Last Day of Current Week. For monthly aggregation, select First Day of Current Month or Last Day of Current Month.
- Click SAVE.
These actions aggregate page views successfully for each company either weekly or monthly. You can then setup any action on this data in the Setup Action page. For more information on how to set rule actions, check the article Setup Rule Action Types.