summaryrefslogtreecommitdiff
path: root/lib/api/usage_data.rb
blob: fa5bfc1cbe978404ca706d5321ec0705ceab9f78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module API
  class UsageData < ::API::Base
    before { authenticate! }

    namespace 'usage_data' do
      before do
        not_found! unless Feature.enabled?(:usage_data_api, default_enabled: true)
        forbidden!('Invalid CSRF token is provided') unless verified_request?
      end

      desc 'Track usage data events' do
        detail 'This feature was introduced in GitLab 13.4.'
      end

      params do
        requires :event, type: String, desc: 'The event name that should be tracked'
      end

      post 'increment_unique_users' do
        event_name = params[:event]

        increment_unique_values(event_name, current_user.id)

        status :ok
      end
    end
  end
end