英文:
googleanalyticsR : How can I get page categories (content group) data?
问题
I am trying to get data on page categories from Analytics, but it seems that this variable does not exist, as looked on https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/.
如果您知道如何获取这些数据,那么其他问题就不适用。
If this indeed does not exists, those are the steps that I follow to get "grouped pages" data:
如果确实不存在,那么这些是我获取“分组页面”数据所采取的步骤:
-
In order to get page data, I use the
dim_filter
argument -
为了获取页面数据,我使用了
dim_filter
参数 -
I define all the pages I need in
all.pages
-
我在
all.pages
中定义了我需要的所有页面 -
The
function (x)
allows for the iteration over the different page names -
function (x)
允许对不同的页面名称进行迭代 -
The actual iteration is done with the
map
function where I passall.pages
through thefunction (x)
-
实际的迭代是通过
map
函数完成的,我通过function (x)
将all.pages
传递给它 -
Then, I create a dataframe
-
然后,我创建一个数据框
-
Because the actual name of the page used in the regex is not in the dataframe, I add them with the mutate function
-
因为正则表达式中使用的页面的实际名称不在数据框中,我使用mutate函数将它们添加进去
This works when there is no dimension but it is rather impossible to do with even a single dimension because the number of rows will not be the same as the length of all.pages
.
这在没有维度时可以工作,但是即使只有一个维度也几乎不可能完成,因为行数将与all.pages
的长度不同。
Would anyone know how to overcome this ?
有人知道如何克服这个问题吗?
Thanks in advance to all of you !
提前感谢大家!
Best, D.
最好,D.
英文:
I am trying to get data on page categories from Analytics, but it seems that this variable does not exist, as looked on https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/.
If you do know how to get this data, the rest of the question does not apply.
If this indeed does not exists, those are the steps that I follow to get "grouped pages" data:
- In order to get page data, I use the
dim_filter
argument - I define all the pages I need in
all.pages
- The
function (x)
allows for the iteration over the different page names - The actual iteration is done with the
map
function where I passall.pages
through thefunction (x)
- Then, I create a dataframe
- Because the actual name of the page used in the regex is not in the dataframe, I add them with the mutate function
all.pages <- c("page.name.1","page.name.2","page.name.3")
pages.ga <- function (x) { x.pages <- dim_filter(dimension="pagePath",operator="REGEXP",expressions=x)
x.filter <- filter_clause_ga4(list(x.pages))
x.results <<- google_analytics(ga_id,
date_range = c("2019-09-01","2019-11-30"),
metrics = c("bounceRate","pageviews","avgTimeOnPage"),
dim_filters = x.filter,
max = -1)
}
list.pages.results <- map(all.pages,pages.ga)
df.pages <- dplyr::bind_rows(list.pages.results)
df.pages <- df.pages %>% mutate(page.name = all.pages)
This works when there is no dimension but it is rather impossible to do with even a single dimension because the number of rows will not be the same as the length of all.pages
.
Would anyone know how to overcome this ?
Thanks in advance to all of you !
Best, D.
答案1
得分: 2
它存在于内容组
ga:contentGroupXX
其中XX是一个整数。为了让事情变得更简单些,您可以前往查询资源,在维度下输入内容组。您可用的整数将自动填充,您可以探索哪个整数是您要寻找的。
英文:
It exists under content group
ga:contentGroupXX
Where XX is an integer. To keep things a bit simpler, it would be easier if you go to query explorer and type in content group under dimensions. The integers you have available will populate and you can explore which integer is the one you seek.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论