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:
- Integrate GA with Kuroco from the admin panel
- Set the custom dimensions
- Embed Google tags on the front-end site
- Set up an additional field for page views in your content structure
- Set the number of page views retrieved as content data
- 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.
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
:
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:
'google-gtag': {
id: 'UA-XXXXXXXXX',
send_page_view: false
},
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:
4. Set up an additional field for page views in your content structure
*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}
Available parameters
The following parameters are available for the GA plugin:
Parameter | Description |
---|---|
var | Variable name assigned to the retrieved result |
viewId | View ID in GA |
update_column_slug | Slug of the column to be updated |
update_column_index | Number of columns to be updated (for repeating columns) |
update_target_metric | Metric used (default: ga:pageviews ) |
update_target_dimension | Dimension used (default: ga:pagePath ) |
topics_group_id | Target content structure ID |
startDate | Counter start date (default: 7 days ago ) |
endDate | Counter end date (default: today ) |
queries | Direct query specifications |
6. Create a list API to retrieve the views of 10 pages in descending order for ranking generation
Field | Value |
---|---|
Category | Content |
Model | Topics |
Operation | list |
Parameter |
|