Class: Sendgrid::Web::Statistics

Inherits:
Client
  • Object
show all
Defined in:
lib/sendgrid/web/statistics.rb

Instance Method Summary collapse

Methods inherited from Client

base_uri, config, #config, configure

Instance Method Details

#get(days: nil, start_date: nil, end_date: nil, aggregate: nil, list: nil, category: nil) ⇒ Sendgrid::Web::Response

Note:

All parameters are optional.

Retrieve statistics and data about your use of SendGrid.

Parameters:

  • days (Integer) (defaults to: nil)

    Number of days in the past to include statistics (Includes today).

  • start_date (DateTime) (defaults to: nil)

    The start date to look up statistics.

  • end_date (DateTime) (defaults to: nil)

    The end date to look up statistics.

  • aggregate (Integer) (defaults to: nil)

    This is used to indicate you are interested in all-time totals.

  • list (bool) (defaults to: nil)

    Determins if SendGrid should return a list of categories.

  • category (String) (defaults to: nil)

    The category you will specify to retrieve detailed stats.

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sendgrid/web/statistics.rb', line 17

def get(
  days: nil, start_date: nil, end_date: nil,
  aggregate: nil, list: nil, category: nil)
  res = connection.post(
    '/api/stats.get.json',
    default_params(
      days: days,
      start_date: start_date,
      end_date: end_date,
      aggregate: aggregate,
      list: list,
      category: category))
  craft_response(res)
end

#get_advanced(data_type: nil, start_date: nil, end_date: nil, metric: nil, category: nil, aggregated_by: nil, country: nil) ⇒ Sendgrid::Web::Response

Note:

The data_type and start_date parameters are required.

Retrieve more advanced and in-depth statistics.

Parameters:

  • data_type (String) (defaults to: nil)

    Must be one of the following:

    • browsers: Browser data obtained from click events.

    • clients: Email client data obtained from open events.

    • devices: Device data obtained from open events.

    • geo: Geographical data obtained from multiple events.

    • global: Global account data obtained from multiple events.

    • isps: ISP data obtained from multiple events.

  • start_date (String) (defaults to: nil)

    Date format is based on aggregated_by value (default is yyyy-mm-dd):

    • yyyy-mm-dd (i.e 2012-12-13) if aggregated_by=day (default)

    • yyyy-ww (i.e 2012-43) if aggregated_by=week

    • yyyy-mm (i.e 2012-11) if aggregated_by=month

  • end_date (String) (defaults to: nil)

    Date format is based on aggregated_by value (default is yyyy-mm-dd):

    • yyyy-mm-dd (i.e 2012-12-13) if aggregated_by=day (default)

    • yyyy-ww (i.e 2012-43) if aggregated_by=week

    • yyyy-mm (i.e 2012-11) if aggregated_by=month

  • metric (String) (defaults to: nil)

    One of the following (default is all):

    • open: Opens

    • click: Clicks

    • unique_open: Unique opens

    • unique_click: Unique clicks

    • processed: Processed emails

    • delivered: Delivered emails

    • drop: Dropped emails

    • bounce: Bounced emails

    • deferred: Deferred email tries

    • spamreport: Emails marked as spam

    • blocked: Emails that have been blocked

    • all: All metrics are returned

  • category (String) (defaults to: nil)

    Return stats for the given category.

  • aggregated_by (String) (defaults to: nil)

    Aggregate the data by the given period (default is day):

    • day: Keys are returned in the format yyyy-mm-dd (i.e 2012-12-13)

    • week: Keys are return in the format yyyy-ww (i.e 2012-43)

    • month: Keys are return in the format yyyy-mm (i.e 2012-11)

  • country (String) (defaults to: nil)

    Get stats for each region/state for the given country. Only US (United States) and CA (Canada) is supported at this time. Country code is two letter characters based on ISO 3166-1 alpha-2.

    This parameter is only used for when data_type=geo

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/sendgrid/web/statistics.rb', line 79

def get_advanced(
  data_type: nil, start_date: nil, end_date: nil,
  metric: nil, category: nil, aggregated_by: nil,
  country: nil)
  if data_type.nil?
    raise ArgumentError.new('Missing required `data_type` option')
  elsif start_date.nil?
    raise ArgumentError.new('Missing required `start_date` option')
  end
  res = connection.post(
    '/api/stats.getAdvanced.json',
    default_params(
      data_type: data_type,
      start_date: start_date,
      end_date: end_date,
      metric: metric,
      category: category,
      aggregated_by: aggregated_by,
      country: country))
  craft_response(res)
end