Tracking of Pageviews and Unique Users at Category and Tag Level

I am curious if you have advice on tracking community health metrics at the category and/or tag level.
For example, I’d love to have a clearer sense of the daily number of pageviews and user visits (both known and anonymous users, and ideally by specific group-members) on topic-threads under each category and tag.

In /admin/dashboard/reports, new topics and new post have reports that can be filtered to the category level, user profile_views can be filtered by group, and there are sitewide metrics on page views and other useful info.

I suspect some of this can be set-up somehow in Google Analytics, but that’s not obvious to me since it’s not obvious how to associate topic urls with tags and categories in google analytics. I also suspect this may be done via the /admin/plugins/explorer, but I haven’t had any success.

Your advice would be greatly appreciated.

「いいね!」 4

Do you have any advice here @hawk? It seems like a reasonable question and maybe new dashboard / reports covers this a bit?

「いいね!」 2

It does seem like a reasonable request, yes. At the moment the reports on the dashboard aren’t segment-able but if we can work out a way to do that I think it would be an excellent addition to v2. We’ve also talked about exposing approved Data Explorer queries on the dashboard.

cc @j.jaffeux – do you have plans to revisit the dashboard any time soon?

「いいね!」 6

Yes, it will be step by step but might come to something close to this. I don‘t want it to become too complex though and it will never be a “combine any segment you want”, there’s sql (and data-explorer) for this. But will probably try to provide this on a per report basis where we think it makes sense.

「いいね!」 4

This query is specifically about pageviews per category, which I don’t think can be handled with Data Explorer can they?

「いいね!」 2

Yes, I would also be interested in a report about the unique users on my site.

Yes this specific report is using ApplicationRequest table, which doesn’t have any notion of category. So not possible through reports, data-explorer or raw sql.

「いいね!」 2

Can we pull a report on the number of anonymous users instead of the number of pages viewed anonymously?

「いいね!」 1

Do you mean the number of people that have used the anonymous posting feature? They all get unique anonymous usernames so it will be very easy to pull a report from Data Explorer

「いいね!」 2

I’m trying to find out how many people are visiting the site who have not logged in at all and do not have an account.

「いいね!」 2

Would love to see this as well! Any advice on how to construct a query? Thx!

We also want this number (PVs per category, excluding crawler activity). Is there a way to get this from the Data Explorer?

I don’t believe so. We don’t granularly track page views like that. You would need to hook up your GA and use that.

「いいね!」 1

@HAWK: Do you reckon this won’t be possible then? Counting Pageviews for users (non-staff, non-crawler)

Has anyone found a solution to count page views for all posts within a specific category? Possible with GA?

「いいね!」 1

Data Explorer を使用すると、カテゴリ内のすべてのトピックのビューを合計することで、合計 カテゴリビューを取得できます。

SELECT 
       c.id as category_id, 
       SUM(views) as "total views"
FROM categories c 
JOIN topics t ON t.category_id = c.id
WHERE read_restricted is false
GROUP BY c.id
order by sum(views) desc

タグごとの合計ビューを取得するのも同様です。

SELECT tags.name,
       sum(views)
from topics t
     join topic_tags tt on t.id = topic_id
     join tags on tags.id = tt.tag_id
group by tags.name
order by sum(views) desc

理論的には、ユーザーと日付でビューを分割するために使用できる topic_views テーブルもあります。しかし、トピックにビューが多いとクエリがタイムアウトするため、このテーブルはあまり役に立たないことがわかりました。また、トピックあたりのビュー数が大幅に少なく表示されます。これは、正しく理解していれば、匿名ビューをカウントしていないためです。また、topic.views には匿名ビューだけでなく、ボットのトラフィックも含まれる可能性があると思います。これは、GA で表示される数よりもはるかに多いです。

GA について言えば、必要なデータはすべて揃っていますが、カテゴリまたはタグでグループ化するのは簡単ではありません。私ができる最善の方法は、pageTitle を解析してカテゴリを見つけようとすることです。これは R で googleAnalyticsR を使用して行っています。マニュアルの指示に従って Google アカウントを認証し、必要なメトリクスを取得してください。ディメンションとして pageTitle を含めることを忘れないでください。私の API 呼び出しは次のようになります。

ga_this_year <- ga_data(ga_id, 
                        date_range = c("2023-01-01", "2023-05-30" ),
                        metrics=c("screenPageViews","averageSessionDuration", "sessions"), 
                        dimensions = c("pageTitle", "deviceCategory")
                       )

次の部分を理解する鍵は、pageTitles がこの一般的な形式に適合することを確認することです。

Topic title - Category - Site title

トピックがカテゴリ化されていない場合、Category は欠落しています。また、カテゴリがないユーティリティページ(「最新トピック」、「新規トピック」など)も多数あります。(「最新 [カテゴリ] トピック」はカテゴリの一部とは見なしていませんが、含めた方が良いかもしれません。)最後に、ホームページでは Site title - short site description がページタイトルとして使用されます。しかし、これらのいずれにも関心はありません。したがって、私が使用している正規表現は次のとおりです。

str_extract(pageTitle,
            str_glue(".*? - (.*) - {sitename}"),
            group=1)

これをカテゴリでグループ化する関数にまとめると、次のようになります。

category_views <- function(data, sitename = "Meta Jon") {
  data %>% 
  mutate(category = str_extract(
                                pageTitle,
                                str_glue(".*? - (.*) - {sitename}"),
                                group=1
                                )) %>% 
  group_by(category) %>% 
  summarise(views = sum(screenPageViews)) %>% 
  arrange(desc(views)) #%>% head(20)
}

category_views(ga_this_year)

(明らかに、「Meta Jon」を自分のサイトの名前に変更してください。)

現時点では、タグに基づいて GA データを抽出する方法はわかりません。

「いいね!」 2

それらの総ビューには、ボット、または匿名ユーザーも含まれていますか?

GA はボット トラフィックを除外します。これは公式ドキュメントによります。topic_views のドキュメントは見つかりませんが、コード内のコメントには次のように書かれています。

# 1 日あたり、1 つの項目あたり、(ユーザー || IP) ごとに 1 回だけビューを保存します

確実ではありませんが、topic.views は GA よりも多くのビューを表示するため、ボットによるページビューを表示しているようです。

Discourse のカウントはデータエクスプローラーを使用した場合ですか?

以前 GA も同じことを言っていましたし、正当なボットがいる場合はそれが真実である可能性があります。しかし、ほとんどの呼び出しは不正なボット、悪質な SEO ボット、クローラーなどによって行われ、その場合、1 回の訪問ルールが破られます。正直に言うと、私はそう思います。

とにかく、私は Matomo を使用しています。GA が必要になるような大物ではありません。

FYI、これは実際には topic_views テーブルが 1日あたりの新しい表示を1回だけカウントする のに対し、topics.views フィールドは8時間ごとに新しい表示を1回カウントする(デフォルトでは変更可能ですが、topic view duration hours で変更できます)ためです。ユーザーと匿名ユーザーの両方が含まれます。:+1:

更新
判明したところによると、topic_views テーブルは1日あたりの新しい表示を1回カウントしているわけではありません…実際には、誰かがトピックを初めて表示したときにカウントし、それ以降の表示はカウントしません。そのため、ユーザーまたはIPごとにトピックあたりのレコードは1つだけになります。

「いいね!」 2