Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for tracking dimesions/metrics #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/tracky_dacks/handlers/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module TrackyDacks
module Handlers
class Event < GA
def call(params = {})
tracker.event(
hit = tracker.build_event(
document_location: params["location"],
document_title: params["title"],
document_path: params["path"],
Expand All @@ -13,6 +13,9 @@ def call(params = {})
action: params["action"],
label: params["label"],
)
add_custom_dimensions(hit, params)
add_custom_metrics(hit, params)
hit.track!
end
end
end
Expand Down
24 changes: 24 additions & 0 deletions lib/tracky_dacks/handlers/ga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ def build_tracker(options)

Staccato.tracker(tracking_id, client_id, options)
end

def add_custom_dimensions(hit, params)
params.select {|param|
param.start_with? "cd"
}.each do |param, value|
dimension_index = param.gsub(/\Acd/, "")
hit.add_custom_dimension(
dimension_index,
value
)
end
end

def add_custom_metrics(hit, params)
params.select {|param|
param.start_with? "cm"
}.each do |param, value|
metric_index = param.gsub(/\Acm/, "")
hit.add_custom_metric(
metric_index,
value
)
end
end
end
end
end
5 changes: 4 additions & 1 deletion lib/tracky_dacks/handlers/pageview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module TrackyDacks
module Handlers
class Pageview < GA
def call(params = {})
tracker.pageview(
hit = tracker.build_pageview(
document_location: params["location"],
document_title: params["title"],
document_path: params["path"],
Expand All @@ -16,6 +16,9 @@ def call(params = {})
campaign_content: params["campaign_content"],
campaign_id: params["campaign_id"]
)
add_custom_dimensions(hit, params)
add_custom_metrics(hit, params)
hit.track!
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/tracky_dacks/handlers/social.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module TrackyDacks
module Handlers
class Social < GA
def call(params = {})
tracker.social(
hit = tracker.build_social(
document_location: params["location"],
document_title: params["title"],
document_path: params["path"],
Expand All @@ -13,6 +13,9 @@ def call(params = {})
network: params["network"],
target: params["target"],
)
add_custom_dimensions(hit, params)
add_custom_metrics(hit, params)
hit.track!
end
end
end
Expand Down