Class: Forem::Services::AnalyticsService

Inherits:
BaseService show all
Defined in:
lib/forem/services/analytics_service.rb

Overview

Service for interacting with the Forem Analytics API.

Provides engagement and traffic data for articles and organizations. Access via Client#analytics. All methods inject the client's requestor automatically so no additional configuration is required.

Examples:

client = Forem::Client.new("your-api-key")
totals = client.analytics.totals(username: "jsmith")
daily  = client.analytics.historical(username: "jsmith", start: "2024-01-01")

See Also:

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from Forem::Services::BaseService

Instance Method Details

#historical(params = {}, opts = {}) ⇒ Array<Analytics>

Retrieve historical engagement metrics broken down by day.

Examples:

client.analytics.historical(
  username: "jsmith",
  start: "2024-01-01",
  end: "2024-03-31"
)

Parameters:

  • params (Hash) (defaults to: {})

    query parameters

  • opts (Hash) (defaults to: {})

    per-request options

Options Hash (params):

  • :username (String)

    filter by author username

  • :organization_id (String)

    filter by organization ID

  • :start (String)

    start date in ISO 8601 format (e.g. "2024-01-01")

  • :end (String)

    end date in ISO 8601 format

Returns:

  • (Array<Analytics>)

    daily breakdown of engagement metrics

See Also:



56
57
58
# File 'lib/forem/services/analytics_service.rb', line 56

def historical(params = {}, opts = {})
  Analytics.historical(params, opts_with_requestor(opts))
end

#past_day(params = {}, opts = {}) ⇒ Analytics

Retrieve engagement metrics for the past 24 hours.

Examples:

client.analytics.past_day(username: "jsmith")

Parameters:

  • params (Hash) (defaults to: {})

    query parameters

  • opts (Hash) (defaults to: {})

    per-request options

Options Hash (params):

  • :username (String)

    filter by author username

  • :organization_id (String)

    filter by organization ID

Returns:

See Also:



72
73
74
# File 'lib/forem/services/analytics_service.rb', line 72

def past_day(params = {}, opts = {})
  Analytics.past_day(params, opts_with_requestor(opts))
end

#referrers(params = {}, opts = {}) ⇒ Array<Analytics>

Retrieve referrer traffic data for a user or organization's content.

Examples:

client.analytics.referrers(username: "jsmith")

Parameters:

  • params (Hash) (defaults to: {})

    query parameters

  • opts (Hash) (defaults to: {})

    per-request options

Options Hash (params):

  • :username (String)

    filter by author username

  • :organization_id (String)

    filter by organization ID

Returns:

  • (Array<Analytics>)

    referrer breakdown showing traffic sources

See Also:



88
89
90
# File 'lib/forem/services/analytics_service.rb', line 88

def referrers(params = {}, opts = {})
  Analytics.referrers(params, opts_with_requestor(opts))
end

#totals(params = {}, opts = {}) ⇒ Analytics

Retrieve total engagement metrics for a user or organization.

Returns all-time totals for page views, reactions, comments, and follows.

Examples:

client.analytics.totals(username: "jsmith")

Parameters:

  • params (Hash) (defaults to: {})

    query parameters

  • opts (Hash) (defaults to: {})

    per-request options

Options Hash (params):

  • :username (String)

    filter metrics by author username

  • :organization_id (String)

    filter metrics by organization ID

Returns:

See Also:



33
34
35
# File 'lib/forem/services/analytics_service.rb', line 33

def totals(params = {}, opts = {})
  Analytics.totals(params, opts_with_requestor(opts))
end