Permalink
Browse files

Add dynamic advanced segments.

  • Loading branch information...
1 parent f4cb3b8 commit f4935eb0e6a38e703380b85f6c47574480f4ed98 @knaveofdiamonds committed Oct 16, 2012
Showing with 24 additions and 1 deletion.
  1. +12 −1 lib/google_analytics_feeds.rb
  2. +12 −0 spec/request_spec.rb
View
13 lib/google_analytics_feeds.rb
@@ -326,12 +326,23 @@ def max_results(i)
#
# @return [GoogleAnalyticsFeeds::DataFeed]
def filters(&block)
- builder =
clone_and_set {|params|
params['filters'] = FilterBuilder.new.build(&block)
}
end
+ # Use a dynamic advanced segment.
+ #
+ # Block methods follow the same style as for filters. Named
+ # advanced segments are not yet supported.
+ #
+ # @return [GoogleAnalyticsFeeds::DataFeed]
+ def segment(&block)
+ clone_and_set {|params|
+ params['segment'] = "dynamic::" + FilterBuilder.new.build(&block)
+ }
+ end
+
# Sorts the result set by a column.
#
# Direction can be :asc or :desc.
View
12 spec/request_spec.rb
@@ -57,4 +57,16 @@
"filters" => "ga:baz==4;ga:foo=@123"
}
end
+
+ it "can add a dynamic segment" do
+ feed = described_class.new.
+ segment {
+ eql :medium, "referral"
+ }
+
+ uri = Addressable::URI.parse(feed.uri)
+ uri.query_values.should == {
+ "segment" => "dynamic::ga:medium==referral"
+ }
+ end
end

0 comments on commit f4935eb

Please sign in to comment.