ATTENTION: THIS IS OUR OLD SITE. TO SEE OUR NEW WEBSITE, CLICK HERE.
This code example shows how to count items of a certain type in a collection and present it as a summary of counts in a table.
The screenshot below shows the code results in a table: counting each time a keyword was searched for by users of a website.
The data being summarised is shown in the collection screenshot below. The collection is called SearchHist (note: this example code does not show you how to capture the search results into a collection). The table is given the id of #aggTable and is defined in the code. No datasets are required in this example as the collection will be directly referenced.
The code is shown below. First, #aggTable is defined. Then the data in the SearchHist collection is extracted to an array called dataArray. Thereafter, the search terms are extracted from dataArray into a new array called termsArray. Duplicate search terms may exist in termsArray as more than one user can search for the same keyword. Then unique search terms are extracted from termsArray into a new array called uniqueTermsArray. Each item of termsArray is looped through each item of uniqueTermsArray, counting each instance of termsArray for every uniqueTermsArray. The result is a count of search terms for each unique search term. This is saved in countArray. The combineArray function is defined and used to combine uniqueTermsArray and countArray. The result of which is saved into a new array called tableArray which is used to populate the table.
The datapath variable in the table definition needs to match the variables fed it in tableArray.
Please login or sign-up (it's free!) to view our code. Refresh the page if already logged in.
Disclaimer: To the best of our knowledge, this code works for its stipulated purpose. If you find an error in our code, or know of a better way to achieve the same result - please contact us! We will help where we can, however please be aware that the code is provided 'as is' and without a promise of support in using or implementing it.