Closed marisveide closed 4 years ago
Hi Maris,
how do you call rack-tracker? how does your controller code look like? I am not super familar with google global, but the rack tracker google global template should be pretty flexible: https://github.com/railslove/rack-tracker/blob/master/lib/rack/tracker/google_global/template/google_global.erb#L20
Hi, @bumi !
Thank you for the reply - this gives hope that I am just not using it correctly.
def gg_purchase
gg_options = {}
gg_options[:action] = 'purchase'
gg_options[:value] = 1
gg_options[:currency] = 'USD'
gg_options[:transaction_id] = 1
gg_options[:label] = 'Basic'
gg_options[:quantity] = 1
gg_options[:items] = [{ "name": 'Basic', "quantity": 1, "price": 1 }]
data = {
type: 'event',
}.merge(gg_options)
if tracker { |t|
t.google_global :event, data
}
end
end
<script asyncsrc='https://www.googletagmanager.com/gtag/js?id=UA-98918029-1'></script>
<script>
window.dataLayer = window.dataLayer \|\| [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'UA-98918029-1', {});
gtag('config', 'UA-98918029-3', {});
gtag('config', 'UA-98918029-4', {});
gtag('config', 'UA-102016273-1', {});
gtag('config', 'UA-102016273-2', {});
gtag('event', 'purchase', {"event_label":"Basic","value":1});
</script>
As you can see, not all options are passed there.
And this Purchase event, therefore, is not appearing in Google Analytics, because the transaction_id
is definitely mandatory.
initializers/rack_tracker.rb
file:if Rails.env.production? || true
Rails.application.config.middleware.use(Rack::Tracker) do
handler :google_global, {
trackers: [
{ id: 'UA-98918029-1' },
{ id: 'UA-98918029-3' }
{ id: 'UA-98918029-4' },
{ id: 'UA-102016273-1' },
{ id: 'UA-102016273-2' },
]
}
end
As far as I found, here's the place which actually accepts only the category
, label
and value
params, and filters everything else off:
https://github.com/railslove/rack-tracker/blob/master/lib/rack/tracker/google_global/google_global.rb#L18
Thanks so much for your help!
ok, yes, looks good. I think (that if
is probably not needed?)
and yeah, you are right. parameters are filtered. Do you want to create a PR adding more possible parameters to that list?
Also have a look at the conversation in the PR adding this feature: https://github.com/railslove/rack-tracker/pull/126
Thanks, @bumi !
OK, I am ready to make the proposed change - and the direction I am thinking is to remove the filtering of those attributes completely. To pass to gtag
all the attributes which were provided from the options.
That is, why duplicate this specification in Ruby code, where for example, for Enhanced ecommerce you can pass all those attributes:
https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce
Do you have any reason why those need to be filtered at all?
@marisveide nice, that would be awesome.
I honestly don't know the details about gtag events, maybe @atd (who developed that feature) remembers why those filters were added.
Hi @bumi @marisveide
I added them to reproduce the existing behavior in the google_analytics
tracker https://github.com/railslove/rack-tracker/blob/master/lib/rack/tracker/google_analytics/google_analytics.rb#L20
But I agree, I think it would be more convenient to drop them and gain in flexibility
Alright, change made, PR made, checks passed (except for one, which looks like build config issue)... You == merge? ;)
In Google Global - to track the
purchase
event, the required field istransaction_id
. At the moment, if we send only thevalue
for the purchase, it's actually not showing up in Google Analytics.It doesn't work if we send the following request (it's how currently rack-tracker is sending the purchase event):
It only shows up in Google Analytics if we send the request like this:
What should I do to send it with the all required attributes?
Ideally, even with attributes like this:
Thanks so much!
Maris