Use case 2 (GA) – customize imported test
In this use case we describe the process of importing and customizing tests on an example of checking for expected domains using Google Analytics data. For multiple domains website, it is possible that sometimes there appear domains which are not supposed to be covered in measurement. This test checks if no necessary domain has disappeared and if there are any unexpected and generally unwanted domains. The test needs to be imported through library and then configured.
-
Go to the Template Gallery tab
-
Select one of the Cross Masters test collections available for the Google Analytics data: Waaila - Hostnames (multi-domain)
-
Create a dataset from the template
-
click on "Use in dataset" button
-
specify an existing depot (if you don't have any depots, create a depot before you start creating a dataset)
-
select "Create a new dataset"
-
select a provider account (email which has an access to your Google Analytics data)
-
you can specify custom name, description and tags for the dataset
Confirming the settings creates the dataset and opens it at the selected location.
-
-
Open the Expected domains test by clicking on its name.
-
Check the Test configuration that is at the top inside the Test logic field and adjust it based on your expectations of domains in the data
- necessaryDomainsArray should specify a list of domains that are required to be present in the data
- permittedDomainsArray should specify list of all domains that are allowed to be present in the data (therefore it needs to include all domains specified in the necessaryDomainsArray)
-
Run the test (the Run button is located above the Query logic)
-
Check the output table.
- If any domains that you specified in the necessaryDomainsArray are missing in the data, you will receive the following message along with a list of the missing domains: 'There are some necessary domains that are missing in the data'
- If there are any domains not specified in the permittedDomainsArray, you will receive the following message along with a table including overview of all domains: 'There are some sessions on unexpected domains'
-
Adjust the configuration if the results are warning against states that are OK.
-
After you customize the test to fail if and only if there is some missing or unwanted domain, save the test.
-
To exit the editor, navigate using the navigation line above the information about the test.
For reference, the Test logic of the test (with the default configuration) is below:
(results, waaila) => {
// < Test configuration starts >
// run the test once and based on the results configure the following arrays
const necessaryDomainsArray = ['main-domain.com', 'other-domain.com']; // list of domains that are required to be present in the data
const permittedDomainsArray = ['main-domain.com', 'other-domain.com', 'N/A']; // list of all domains that are allowed to be present in the data
// < Test configuration ends >
const domainSessions = waaila.functions.normalizeGaResult(results['domainSessions'][0]);
// 1) none of the necessary domains disappeared
currentDomainsArray = domainSessions.map(function (row){
return row['hostname'];
});
let missingDomainsArray = necessaryDomainsArray.filter(function (domain) {
return currentDomainsArray.includes(domain) == false;
});
const assert_pass_message_blackout = 'No necessary domains are missing in the data';
const assert_fail_message_blackout = 'There are some necessary domains that are missing in the data: ' + missingDomainsArray.join(', ') ;
waaila.assert(typeof missingDomainsArray[0] === 'undefined', 60)
.pass.message(assert_pass_message_blackout).fail.message(assert_fail_message_blackout);
// 2) there is no unexpected domain included
domainSessions.forEach(function (row) {
if (permittedDomainsArray.includes(row['hostname'])){
row['expected'] = 'OK'
} else {
row['expected'] = 'NOT'
}
})
const unexpectedDomains = domainSessions.filter(row => row['expected'] == 'NOT');
const assert_pass_message_unexpected = 'No unexpected domains are measured in the data.' ;
const assert_fail_message_unexpected = 'There are some sessions on unexpected domains:' ;
waaila.assert((typeof unexpectedDomains[0] === 'undefined'), 60)
.pass.message(assert_pass_message_unexpected)
.fail.message(assert_fail_message_unexpected)
.table(domainSessions, [{'column': 'expected', 'condition': {'EQUAL' : 'OK'}}]);
}