Implementing view-based page rankings in Google Analytics

To implement a ranking based on the number of page views in Google Analytics (GA), you need to do the following:

  1. Integrate GA with Kuroco from the admin panel
  2. Set the custom dimensions
  3. Embed Google tags on the front-end site
  4. Set up an additional field for page views in your content structure
  5. Set the number of page views retrieved as content data
  6. Create a list API to retrieve the views of 10 pages in descending order for ranking generation

1. Integrate GA with Kuroco from the admin panel

See Tutorial: How to link Google Analytics for a detailed guide.

Currently, integration with GA4 is not available. Therefore, to obtain the number of page views, you need to use Universal Analytics in addition to GA4.

In addition to the above settings, "Google Analytics Reporting API" must be enabled.

Image from Gyazo

2. Set the custom dimensions

Set either content ID or slug as a custom dimension value, based on your front-end configurations. Either option is fine, since both are used to specify the viewed content.

Example using slug:

Image from Gyazo

3. Embed Google tags on the front-end site

See Tutorial: How to link Google Analytics for a detailed guide on how to configure the front-end. 

In this tutorial, we will only retrieve the page views for the content pages we want to rank. Therefore, we will send the page_view event as a mounted embedding:

nuxt.config.js
  'google-gtag': {
    id: 'UA-XXXXXXXXX',
    send_page_view: false
  },
Mounting on the content page
if (process.client) {
    const slug = // Retrieve slug from page URL, etc.
    this.$gtag('event', 'page_view', {
        'dimension1': slug
    })
}

Replace UA-XXXXXXXXX in the above code with your unique Tracking ID, which you can view under [Tracking Info] -> [Tracking Code] from the Admin sidebar menu.

Now, verify the front-end display. If the page_view event has been sent correctly, you should be able to check the number of page views by specifying the secondary dimension in the GA console as shown below:

Image from Gyazo

4. Set up an additional field for page views in your content structure

Image from Gyazo

*Make sure you select [Counter] as the field type. *The identifier value entered here will be used when setting the page views in the contents module.

5. Set the number of page views retrieved as content data

Create a batch process as follows to execute SmartyPlugin and set the page views retrieved as content data:

{*Retrieve page view count from GA and set it in the counter*}
{googleanalytics var=result
update_column_slug="pv"
update_target_dimension="ga:dimension1"
updated_topics_ids='updated_topics_ids'
topics_group_id=1}{*Enter the target content structure ID as the topics_group_id*}

{*Reflects data from the counter in the contents data*}
{assign_array var=ext_data values=''}
{assign var=ext_data.topics_ids values=$updated_topics_ids}
{batch module='topics' name='sync_counter' ext_data=$ext_data}

Image from Gyazo Image from Gyazo

Available parameters

The following parameters are available for the GA plugin:

ParameterDescription
varVariable name assigned to the retrieved result
viewIdView ID in GA
update_column_slugSlug of the column to be updated
update_column_indexNumber of columns to be updated (for repeating columns)
update_target_metricMetric used (default: ga:pageviews)
update_target_dimensionDimension used (default: ga:pagePath)
topics_group_idTarget content structure ID
startDateCounter start date (default: 7 days ago)
endDateCounter end date (default: today)
queriesDirect query specifications

6. Create a list API to retrieve the views of 10 pages in descending order for ranking generation

FieldValue
CategoryContent
ModelTopics
Operationlist
Parameter
  • topics_group_id: (target content structure ID)
  • cnt: 10
  • order_query: pv:desc

If you have any other questions, please use our contact form or Slack workspace.