g_ruby 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/g_ruby/analytics.rb +62 -59
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf7759a53575d6479d1b10778938fb30390e9c2d
|
|
4
|
+
data.tar.gz: e850aabc50186eb77aa6b7a0963dc6d9fa75e204
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3724e6611ee774b899eb0612703d5683ceec520cd2c622d4b55249df5822d5f7be83d3e38b6d505c197edb104dfc9b6b545150c818c74f64bff3e8bd74636b3d
|
|
7
|
+
data.tar.gz: 4f6a0340cbc7287a3e8b6b930d4042043e431d6514cb5acd15fc2acd94515506aca012286b6d8ea7b9de43f4fbe3a505b6b67769a9f30e0a9d6923d995738159
|
data/lib/g_ruby/analytics.rb
CHANGED
|
@@ -96,75 +96,78 @@ class GRuby::Analytics
|
|
|
96
96
|
#GRuby::Analytics.get_with_delta(access_token, start_date, end_date, profile_id, metrics, dimensions, sort, max_results)
|
|
97
97
|
def self.get_with_delta(access_token, start_date, end_date, profile_id, metrics, dimensions=nil, sort=nil, limit=nil, refresh=nil)
|
|
98
98
|
#begin
|
|
99
|
+
|
|
100
|
+
response_obj = []
|
|
101
|
+
|
|
99
102
|
d30_days_ago = (Date.today - 30).to_time.strftime("%Y-%m-%d").to_s
|
|
100
103
|
d60_days_ago = (Date.today - 60).to_time.strftime("%Y-%m-%d").to_s
|
|
101
104
|
date_today = Time.now.strftime("%Y-%m-%d")
|
|
102
105
|
|
|
103
106
|
a0 = GRuby::Analytics.get(access_token, start_date, end_date, profile_id, metrics, dimensions, sort, limit)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if a0.class.to_s != "Array"
|
|
108
|
-
return a0 if a0[:status] == "failed"
|
|
109
|
-
elsif a30.class.to_s != "Array"
|
|
110
|
-
return a30 if a0[:status] == "failed"
|
|
111
|
-
elsif a60.class.to_s != "Array"
|
|
112
|
-
return a60 if a0[:status] == "failed"
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
response_obj = []
|
|
107
|
+
if a0.blank?
|
|
108
|
+
a30 = GRuby::Analytics.get(access_token, d30_days_ago, date_today, profile_id, metrics, dimensions, sort, nil)
|
|
109
|
+
a60 = GRuby::Analytics.get(access_token, d60_days_ago, d30_days_ago, profile_id, metrics, dimensions, sort, nil)
|
|
116
110
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if
|
|
123
|
-
response_obj << {tag: metric.gsub("ga:", ""), val: a0[metric], delta: 0, delta_explaination: dd}
|
|
124
|
-
else
|
|
125
|
-
response_obj << {tag: metric.gsub("ga:", ""), val: a0[metric], delta: ((d_this - d_last) * 100 / d_last), delta_explaination: dd}
|
|
126
|
-
end
|
|
111
|
+
if a0.class.to_s != "Array"
|
|
112
|
+
return a0 if a0[:status] == "failed"
|
|
113
|
+
elsif a30.class.to_s != "Array"
|
|
114
|
+
return a30 if a0[:status] == "failed"
|
|
115
|
+
elsif a60.class.to_s != "Array"
|
|
116
|
+
return a60 if a0[:status] == "failed"
|
|
127
117
|
end
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if d_last == 0
|
|
140
|
-
del = 0
|
|
141
|
-
else
|
|
142
|
-
del = ((d_this.to_i - d_last.to_i) * 100 / d_last.to_f)
|
|
143
|
-
end
|
|
144
|
-
response_obj << {tag: metrics.gsub("ga:", ""), val: i[1], dimension: i[0], delta: del, delta_explaination: dd}
|
|
145
|
-
end
|
|
146
|
-
elsif dimensions.split(",").count > 1 and metrics.split(",").count == 1
|
|
147
|
-
a0.each do |i|
|
|
148
|
-
d_this = nil
|
|
149
|
-
d_last = nil
|
|
150
|
-
if dimensions == "ga:source,ga:medium"
|
|
151
|
-
k3 = i[1]=='referral' ? 'OtherSources' : (i[1]=='(none)' and i[0]=="(direct)") ? 'DirectSource' : 'searchEngine'
|
|
152
|
-
elsif dimensions == "ga:keyword,ga:medium"
|
|
153
|
-
k3 = i[1] == 'organic' ? 'OrganicKeywords' : 'PaidKeywords'
|
|
154
|
-
end
|
|
155
|
-
a30.each do |j|
|
|
156
|
-
d_this = j[2] if (j[0] == i[0] and j[1] == i[1])
|
|
118
|
+
|
|
119
|
+
if dimensions.blank?
|
|
120
|
+
metrics.split(",").each do |metric|
|
|
121
|
+
d_this = a30[metric].to_i
|
|
122
|
+
d_last = a60[metric].to_i
|
|
123
|
+
dd = GRuby::Analytics.generate_delta_explaination(d_this, d_last, refresh)
|
|
124
|
+
if d_last == 0
|
|
125
|
+
response_obj << {tag: metric.gsub("ga:", ""), val: a0[metric], delta: 0, delta_explaination: dd}
|
|
126
|
+
else
|
|
127
|
+
response_obj << {tag: metric.gsub("ga:", ""), val: a0[metric], delta: ((d_this - d_last) * 100 / d_last), delta_explaination: dd}
|
|
128
|
+
end
|
|
157
129
|
end
|
|
158
|
-
|
|
159
|
-
|
|
130
|
+
elsif dimensions.split(",").count == 1 and metrics.split(",").count == 1
|
|
131
|
+
a0.each do |i|
|
|
132
|
+
d_this = nil
|
|
133
|
+
d_last = nil
|
|
134
|
+
a30.each do |j|
|
|
135
|
+
d_this = j[1].to_i if j[0] == i[0]
|
|
136
|
+
end
|
|
137
|
+
a60.each do |k|
|
|
138
|
+
d_last = k[1].to_i if k[0] == i[0]
|
|
139
|
+
end
|
|
140
|
+
dd = GRuby::Analytics.generate_delta_explaination(d_this, d_last, refresh)
|
|
141
|
+
if d_last == 0
|
|
142
|
+
del = 0
|
|
143
|
+
else
|
|
144
|
+
del = ((d_this.to_i - d_last.to_i) * 100 / d_last.to_f)
|
|
145
|
+
end
|
|
146
|
+
response_obj << {tag: metrics.gsub("ga:", ""), val: i[1], dimension: i[0], delta: del, delta_explaination: dd}
|
|
160
147
|
end
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
148
|
+
elsif dimensions.split(",").count > 1 and metrics.split(",").count == 1
|
|
149
|
+
a0.each do |i|
|
|
150
|
+
d_this = nil
|
|
151
|
+
d_last = nil
|
|
152
|
+
if dimensions == "ga:source,ga:medium"
|
|
153
|
+
k3 = i[1]=='referral' ? 'OtherSources' : (i[1]=='(none)' and i[0]=="(direct)") ? 'DirectSource' : 'searchEngine'
|
|
154
|
+
elsif dimensions == "ga:keyword,ga:medium"
|
|
155
|
+
k3 = i[1] == 'organic' ? 'OrganicKeywords' : 'PaidKeywords'
|
|
156
|
+
end
|
|
157
|
+
a30.each do |j|
|
|
158
|
+
d_this = j[2] if (j[0] == i[0] and j[1] == i[1])
|
|
159
|
+
end
|
|
160
|
+
a60.each do |k|
|
|
161
|
+
d_last = k[2] if (k[0] == i[0] and k[1] == i[1])
|
|
162
|
+
end
|
|
163
|
+
dd = GRuby::Analytics.generate_delta_explaination(d_this, d_last, refresh)
|
|
164
|
+
if d_last.to_f == 0
|
|
165
|
+
del = 0
|
|
166
|
+
else
|
|
167
|
+
del = ((d_this.to_i - d_last.to_i) * 100 / d_last.to_f)
|
|
168
|
+
end
|
|
169
|
+
response_obj << {tag: i[0], val: i[2], dimension: k3, delta: del, delta_explaination: dd}
|
|
166
170
|
end
|
|
167
|
-
response_obj << {tag: i[0], val: i[2], dimension: k3, delta: del, delta_explaination: dd}
|
|
168
171
|
end
|
|
169
172
|
end
|
|
170
173
|
|