-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First draft of the DSL. Not ready for production yet since JS generation
is somewhat of an issue. Specified the API in a huge data structure for now. If you know some better way to do this, let me know. method_missing is used to check whether a method exists, validate the arguments and add it to list. The list will be converted to valid JS calls (based on use_async?) and rendered out for piwik_tracking_tag. refs #7, #10
- Loading branch information
Showing
7 changed files
with
133 additions
and
6 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
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module PiwikAnalytics | ||
module ControllerHelpers | ||
def piwik_tracking(&block) | ||
yield PiwikAnalytics.tracker | ||
end | ||
end | ||
end |
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
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 +1,2 @@ | ||
ActionView::Base.send :include, PiwikAnalytics::Helpers | ||
ActionView::Base.send :include, PiwikAnalytics::ViewHelpers | ||
ActionController::Base.send :include, PiwikAnalytics::ControllerHelpers |
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
module PiwikAnalytics | ||
class PiwikTracker | ||
|
||
def initialize | ||
@calls = Array.new | ||
end | ||
|
||
def method_missing(meth, *args, &block) | ||
name = meth.to_s.camlize(:lower) | ||
valid_method? name | ||
valid_arguments? args | ||
call = { method: name, args: args } | ||
@calls.push call | ||
end | ||
|
||
def to_s | ||
@calls.each do |call| | ||
|
||
end | ||
end | ||
|
||
private | ||
def valid_method?(name) | ||
@@methods.has_key? name | ||
end | ||
|
||
def valid_arguments?(name, args) | ||
method = @@methods[name] | ||
# Check each argument (name, optional) | ||
method.each do |arg| | ||
unless arg[:optional] | ||
return false unless args.has_key? arg[:name] | ||
end | ||
end | ||
# Return in order | ||
return true | ||
end | ||
end | ||
|
||
@@methods = { | ||
"setDocumentTitle" => [ | ||
{ name: :title, optional: false } | ||
], | ||
"setCustomUrl" => [ | ||
{ name: :url, optional: false } | ||
], | ||
"setReferrerUrl" => [ | ||
{ name: :url, optional: false } | ||
], | ||
"setSiteId" => [ | ||
{ name: :site_id, optional: false } | ||
], | ||
"trackGoal" => [ | ||
{ name: :id_goal, optional: false }, | ||
{ name: :custom_revenue, optional: true } | ||
], | ||
"trackSiteSearch" => [ | ||
{ name: :keyword, optional: false }, | ||
{ name: :category, optional: true, default: false }, | ||
{ name: :search_count, optional: true, default: false } | ||
], | ||
"setCustomVariable" => [ | ||
{ name: :index, optional: false }, | ||
{ name: :name, optional: false }, | ||
{ name: :value, optional: false }, | ||
{ name: :scope, optional: true, default: "visit" } | ||
], | ||
"deleteCustomVariable" => [ | ||
{ name: :index, optional: false }, | ||
{ name: :scope, optional: false } | ||
], | ||
"setCookieDomain" => [ | ||
{ name: :domain, optional: false } | ||
], | ||
"setDomains" => [ | ||
{ name: :domains, optional: false } | ||
], | ||
"setCookiePath" => [ | ||
{ name: :path, optional: false } | ||
], | ||
"setIgnoreClasses" => [ | ||
{ name: :classes, optional: false } | ||
], | ||
"setDownloadClasses" => [ | ||
{ name: :classes, optional: false } | ||
], | ||
"setLinkClasses" => [ | ||
{ name: :classes, optional: false } | ||
], | ||
"setLinkTrackingTimer" => [ | ||
{ name: :time, optional: false } | ||
], | ||
"setDownloadExtensions" => [ | ||
{ name: :extensions, optional: false } | ||
], | ||
"addDownloadExtensions" => [ | ||
{ name: :extensions, optional: false } | ||
], | ||
"enableLinkTracking" => [ | ||
{ name: :enable, optional: false } | ||
], | ||
"setRequestMethod" => [ | ||
{ name: :method, optional: false } | ||
] | ||
} | ||
end |
14 changes: 10 additions & 4 deletions
14
lib/piwik_analytics/helpers.rb → lib/piwik_analytics/view_helpers.rb
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