I created a helper module in Rails that creates a hash of parameters that are passed to link_to
rails helpers. These utm
parameters are being used in emails sent out by the Rails app. The problem is that Google Analytics is not picking up any data when I've been testing. I realize there is a delay in processing and I'm also using the GA debugger to look at the beacons it's actually sending out and I have a staging server and staging Google Analytics that I am testing all of this on. Does anyone see anything with the approach below that would cause GA to not pick up any visits under the "campaigns" report? Does the order of the utm
tags actually matter? I realize utm_campaign
, utm_source
and utm_medium
are all required and ensured they are in every link.
For example, this is what one of the links looks like. However, GA is not picking up any data.
http://example.com/?utm_campaign=welcome&utm_medium=email&utm_source=abc
I compare this link that that the link_to
method has created with to what the Google UTM Link Builder outputs and the only difference is the order of the parameters. Does the order matter?
http://example.com/?utm_source=abc&utm_medium=email&utm_campaign=welcome
Here is the helper module and an example of it's usage with a link_to
.
# mailer_helper.rb
require 'uri'
module MailerHelper
def self.tracking_param_hash(utm_source, utm_medium, utm_campaign, params = {})
{ utm_source: utm_source,
utm_medium: utm_medium,
utm_campaign: utm_campaign
}.merge(params)
end
def self.email_tracking_params(utm_campaign, options = {})
tracking_param_hash("abc", "email", utm_campaign, options)
end
...
end
# example usage in email view
email_params = MailerHelper::email_tracking_params("set-password", reset_password_token: @token)
link_to 'Set my password', edit_password_url(@resource, email_params)
# rendered link in email
http://example.com/users/password/edit?reset_password_token=YEt9PJgQsxb3WpJQ7OEXH3YDT8JZMD&utm_campaign=reset-password&utm_medium=email&utm_source=abc
Data wasn't recording for several reasons. The first one was because one of the link users were clicking on was doing a POST to a user_confirmation_path
. Because the urchin was never loads on the POST, no data will be recorded and users are re-directed to the sign in page. The parameters need to persist with the re-direct from the POST, otherwise traffic will be treated as direct
. Near the end of this Kissmetrics blog post they outline this problem. To get around this, you can pass parameters into the redirect url. So something like redirect_to user_signin_path(tracking_parameters)
, where tracking_parameters
are the utm
tags from the POST URL.
The second was because the utmz
cookie was persisting across and wasn't counting the visit as a new session. You need to test everything in a fresh incognito window because of how Google Analytics and chrome treat individual sessions. See this SO post for more details.
Finally, for anyone who reads this, you can confirm that UTM parameters are being set by looking fora cookie called utmz
. This cookie is used by Google Analytics and will look something like this 12340657.1412743014.15.1.utmcsr=abc|utmccn=confirm|utmcmd=email
and should have the utm
parameters in it.
[Edited for clarity and and the various scenarios I was testing]