Store UTM cookies
This commit is contained in:
parent
71d8571eb9
commit
624853c868
|
|
@ -12,6 +12,7 @@ const MetaTracking = {
|
||||||
const location = window.location;
|
const location = window.location;
|
||||||
this.handleFbc(location.search);
|
this.handleFbc(location.search);
|
||||||
this.handleFbp();
|
this.handleFbp();
|
||||||
|
this.handleUtm(location.search);
|
||||||
},
|
},
|
||||||
|
|
||||||
// 1. Parsing and storing _fbc (Click ID)
|
// 1. Parsing and storing _fbc (Click ID)
|
||||||
|
|
@ -30,6 +31,16 @@ const MetaTracking = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleUtm: function (searchParams) {
|
||||||
|
const utmParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
|
||||||
|
utmParams.forEach(param => {
|
||||||
|
const value = this.getQueryParam(param, searchParams);
|
||||||
|
if (value) {
|
||||||
|
this.setCookie(param, value, 90);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
// 2. Handling _fbp (Browser ID)
|
// 2. Handling _fbp (Browser ID)
|
||||||
handleFbp: function () {
|
handleFbp: function () {
|
||||||
if (!this.getCookie('_fbp')) {
|
if (!this.getCookie('_fbp')) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
var location = window.location;
|
var location = window.location;
|
||||||
this.handleFbc(location.search);
|
this.handleFbc(location.search);
|
||||||
this.handleFbp();
|
this.handleFbp();
|
||||||
|
this.handleUtm(location.search);
|
||||||
},
|
},
|
||||||
|
|
||||||
// 1. Parsing and storing _fbc (Click ID)
|
// 1. Parsing and storing _fbc (Click ID)
|
||||||
|
|
@ -33,6 +34,19 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleUtm: function (searchParams) {
|
||||||
|
var utmParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
|
||||||
|
var self = this;
|
||||||
|
// forEach not supported in IE8, but this is modern enough or we can use for loop
|
||||||
|
for (var i = 0; i < utmParams.length; i++) {
|
||||||
|
var param = utmParams[i];
|
||||||
|
var value = self.getQueryParam(param, searchParams);
|
||||||
|
if (value) {
|
||||||
|
self.setCookie(param, value, 90);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// 2. Handling _fbp (Browser ID)
|
// 2. Handling _fbp (Browser ID)
|
||||||
handleFbp: function () {
|
handleFbp: function () {
|
||||||
if (!this.getCookie('_fbp')) {
|
if (!this.getCookie('_fbp')) {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,9 @@ class ApiRecurlyController < ApiController
|
||||||
reuse_card: reuse_card_next_time,
|
reuse_card: reuse_card_next_time,
|
||||||
affiliate_referral_id: cookies[:affiliate_visitor],
|
affiliate_referral_id: cookies[:affiliate_visitor],
|
||||||
origin: origin_cookie,
|
origin: origin_cookie,
|
||||||
timezone: current_timezone
|
timezone: current_timezone,
|
||||||
|
facebook_click_id: cookies[:_fbc],
|
||||||
|
facebook_browser_id: cookies[:_fbp]
|
||||||
}
|
}
|
||||||
|
|
||||||
options = User.musician_defaults(request.remote_ip, ApplicationHelper.base_uri(request) + "/confirm", any_user, options)
|
options = User.musician_defaults(request.remote_ip, ApplicationHelper.base_uri(request) + "/confirm", any_user, options)
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,22 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
def origin_cookie
|
def origin_cookie
|
||||||
begin
|
begin
|
||||||
JSON.parse(cookies[:origin]) if cookies[:origin]
|
data = JSON.parse(cookies[:origin]) if cookies[:origin]
|
||||||
rescue
|
rescue
|
||||||
nil
|
data = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Backfill with individual UTM cookies if present
|
||||||
|
# This supports cases where the frontend (jam-ui/web) set specific cookies
|
||||||
|
# or if the JSON cookie is missing/incomplete.
|
||||||
|
%w(utm_source utm_medium utm_campaign utm_term utm_content).each do |key|
|
||||||
|
if cookies[key].present?
|
||||||
|
data ||= {}
|
||||||
|
data[key] = cookies[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
def track_origin
|
def track_origin
|
||||||
|
|
|
||||||
|
|
@ -635,6 +635,10 @@ class LandingsController < ApplicationController
|
||||||
musician: true,
|
musician: true,
|
||||||
timezone: current_timezone,
|
timezone: current_timezone,
|
||||||
first_name: @first,
|
first_name: @first,
|
||||||
|
origin: origin_cookie,
|
||||||
|
affiliate_referral_id: cookies[:affiliate_visitor],
|
||||||
|
facebook_click_id: cookies[:_fbc],
|
||||||
|
facebook_browser_id: cookies[:_fbp],
|
||||||
instruments: [{:instrument_id => @instrument, :proficiency_level => 1, :priority => 1}])
|
instruments: [{:instrument_id => @instrument, :proficiency_level => 1, :priority => 1}])
|
||||||
if @user.errors.any?
|
if @user.errors.any?
|
||||||
first = @user.errors.first
|
first = @user.errors.first
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,10 @@ class SessionsController < ApplicationController
|
||||||
last_name: auth_hash[:info][:last_name],
|
last_name: auth_hash[:info][:last_name],
|
||||||
email: auth_hash[:info][:email],
|
email: auth_hash[:info][:email],
|
||||||
timezone: current_timezone,
|
timezone: current_timezone,
|
||||||
affiliate_referral_id: cookies[:affiliate_visitor])
|
affiliate_referral_id: cookies[:affiliate_visitor],
|
||||||
|
origin: origin_cookie,
|
||||||
|
facebook_click_id: cookies[:_fbc],
|
||||||
|
facebook_browser_id: cookies[:_fbp])
|
||||||
|
|
||||||
# Users who sign up using oauth are presumed to have valid email adddresses.
|
# Users who sign up using oauth are presumed to have valid email adddresses.
|
||||||
user.confirm_email!
|
user.confirm_email!
|
||||||
|
|
@ -196,7 +199,9 @@ class SessionsController < ApplicationController
|
||||||
location: {:country => nil, :state => nil, :city => nil},
|
location: {:country => nil, :state => nil, :city => nil},
|
||||||
affiliate_referral_id: cookies[:affiliate_visitor],
|
affiliate_referral_id: cookies[:affiliate_visitor],
|
||||||
origin: origin_cookie,
|
origin: origin_cookie,
|
||||||
timezone: current_timezone
|
timezone: current_timezone,
|
||||||
|
facebook_click_id: cookies[:_fbc],
|
||||||
|
facebook_browser_id: cookies[:_fbp]
|
||||||
}
|
}
|
||||||
|
|
||||||
options = User.musician_defaults(request.remote_ip, ApplicationHelper.base_uri(request) + "/confirm", any_user, options)
|
options = User.musician_defaults(request.remote_ip, ApplicationHelper.base_uri(request) + "/confirm", any_user, options)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue