Create a page view count report

The page view count is stored in the database and is not visible unless you use the SIL Inline Script macro from the Create a page view counter example. In order to get a report of the page views you will need to get the view counts out of the database and create a report.

  1. Create a new file in the SIL Manager called pageViewReport.sil
  2. Paste the following code into the file editor window:

    struct table {
        string Title;
        string Views;
    }
    
    string cql = "(type=page and Space=" + argv[0] + ")";
    number [] pages = selectPages(cql);
    
    table [] tableData;
    
    for(number p in pages) {
        table t;
        t.Title = p.title;
        t.Views = getPersistentVar(p, "counter");
        tableData += t;
    }
    
    return tableData;


  3. Save the file
  4. On a new page add the SIL Table macro
  5. Edit the macro
  6. Select the pageViewReport.sil script for the script setting
  7. Add "Page, View Counts" into the columns setting
  8. Enter the key of the space the page is in for the input setting
  9. Save the macro
  10. Save the new page

When you view the page you should see a report similar to this one show the view counts of the pages in the space: