This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
amironenko
committed
Mar 15, 2016
1 parent
b1982a6
commit 6a50a43
Showing
1 changed file
with
16 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,32 @@ | ||
module Metrika | ||
module Api | ||
module Statistics | ||
# Traffic | ||
%w( summary deepness hourly load ).each do |report| | ||
define_method "get_counter_stat_traffic_#{report}" do | id, params = {} | | ||
params = self.format_params(params) | ||
|
||
self.get(self.send("counter_stat_traffic_#{report}_path"), params.merge(:id => id)) | ||
end | ||
|
||
define_method "counter_stat_traffic_#{report}_path" do | ||
"/stat/traffic/#{report}" | ||
end | ||
end | ||
|
||
# Sources | ||
%w( summary sites search_engines phrases marketing direct_summary direct_platforms direct_regions tags ).each do |report| | ||
define_method "get_counter_stat_sources_#{report}" do | id, params = {} | | ||
params = self.format_params(params) | ||
METRICS = {} | ||
|
||
self.get(self.send("counter_stat_sources_#{report}_path"), params.merge(:id => id)) | ||
%W(#{''} PerDay PerHour PerMinute).each do |interval| | ||
%w(visits pageviews).each do |metric| | ||
METRICS["#{metric}#{interval}".to_sym] = "ym:s:#{metric}#{interval}" | ||
end | ||
|
||
define_method "counter_stat_sources_#{report}_path" do | ||
"/stat/sources/#{report}" | ||
end | ||
end | ||
|
||
# Content | ||
%w( popular entrance exit titles url_param user_vars ecommerce ).each do |report| | ||
define_method "get_counter_stat_content_#{report}" do | id, params = {} | | ||
params = self.format_params(params) | ||
|
||
self.get(self.send("counter_stat_content_#{report}_path"), params.merge(:id => id)) | ||
end | ||
|
||
define_method "counter_stat_content_#{report}_path" do | ||
"/stat/content/#{report}" | ||
end | ||
%w(under18AgePercentage upTo24AgePercentage upTo34AgePercentage upTo44AgePercentage).each do |age_interval| | ||
METRICS["age_#{age_interval}".to_sym] = "ym:s:#{age_interval}" | ||
end | ||
|
||
# Geo | ||
def get_counter_stat_geo(id, params = {}) | ||
params = self.format_params(params) | ||
DIMENSIONS = { gender: "ym:s:gender", country: "ym:s:regionCountry", city: "ym:s:regionCity", | ||
ip: "ys:s:ipAddress", device_type: "ym:s:deviceCategory", device_manufacturer: "ym:s:mobilePhone", | ||
device_model: "ym:s:mobilePhoneModel", OS: "ym:s:operatingSystemRoot", browser: "ym:s:browser", | ||
screen_size: "ym:s:windowClientArea", traffic_sources: "ym:s:<attribution>TrafficSource", | ||
source_engine: "ym:s:<attribution>SourceEngine", advert_engine: "ym:s:<attribution>AdvEngine", | ||
referal_site: "ym:s:<attribution>ReferalSource", social_network: "ym:s:<attribution>SocialNetwork", | ||
referer: "ym:s:referer", interest: "ym:s:interest" } | ||
|
||
self.get(self.counter_stat_geo_path, params.merge(:id => id)) | ||
end | ||
|
||
def counter_stat_geo_path | ||
"/stat/geo" | ||
end | ||
|
||
# Interest | ||
def get_counter_stat_interest(id, params = {}) | ||
def get_counter_stats(id, params = {}) | ||
params = self.format_params(params) | ||
|
||
self.get(self.counter_stat_interest_path, params.merge(:id => id)) | ||
raise Metrika::Errors::GeneralError.new("Provide at least metric for query") if params[:metrics].nil? | ||
self.get("/stat/v1/data", params.merge(id: id)) | ||
end | ||
|
||
def counter_stat_interest_path | ||
"/stat/interest" | ||
end | ||
|
||
# Demography | ||
%w( age_gender structure ).each do |report| | ||
define_method "get_counter_stat_demography_#{report}" do | id, params = {} | | ||
params = self.format_params(params) | ||
|
||
self.get(self.send("counter_stat_demography_#{report}_path"), params.merge(:id => id)) | ||
end | ||
|
||
define_method "counter_stat_demography_#{report}_path" do | ||
"/stat/demography/#{report}" | ||
end | ||
end | ||
|
||
# Tech | ||
%w( browsers os display mobile flash silverlight dotnet java cookies javascript ).each do |report| | ||
define_method "get_counter_stat_tech_#{report}" do | id, params = {} | | ||
params = self.format_params(params) | ||
|
||
self.get(self.send("counter_stat_tech_#{report}_path"), params.merge(:id => id)) | ||
end | ||
|
||
define_method "counter_stat_tech_#{report}_path" do | ||
"/stat/tech/#{report}" | ||
end | ||
end | ||
end | ||
end | ||
end |