HUGO

GetPage using page URL

Hi,
i’m trying to do a most visited pages widget for my blog.
My idea is to get a CSV from Google Analytics, read it, and then use the data to make the page.
My problem is that GA give me the page url ‘/my-page-1’.
How can i get the page data using the URL? Is it possible?

Thanks

I would look into the Google sheet add ons for GA.Then you can use Sheets publish-to-CSV feature. Then check out the docs for data-driven content to see how to pull a CSV from a URL into a template. Keep in mind this will only update every time you build your site…

Hi, thanks for the reply.
Yes, i was thinking about use the data-driven content.
My problem is. After i do that and have the url from the page. How to i get this page data, like title, params, tags, etc…

Is this is a single-content page or a list page? That is, an “article” or “landing/home page” for a section of your site?

If you are putting it on an individual page, you can grab title, etc, directly from the front matter the way you would any other page. If it’s a section/list page, you’ll need to create an _index.md in that section/list.

Just in case somebody like me find this post from and is looking for a solution to get the page from the url, the method I found was:

(index (where .Page.Site.AllPages "Permalink" $pagename) 0)

Which takes the first page where the permalink is equal to $pagename.