Skip to content

Commit

Permalink
v1.8.1
Browse files Browse the repository at this point in the history
Merge pull request #589 from TechforgoodCAST/develop
  • Loading branch information
suninthesky authored Feb 6, 2018
2 parents 83b6a81 + eed17c8 commit 547f2aa
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 24 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ gem 'httparty'
gem 'kaminari'
gem 'nokogiri'
gem 'pundit'
gem 'rack-tracker', git: 'https://github.com/railslove/rack-tracker', branch: 'master'
gem 'redcarpet'
gem 'simple_form'
gem 'sitemap_generator'
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
GIT
remote: https://github.com/railslove/rack-tracker
revision: 5e9d176a2ea865353ef6f515920715f1e93bbeff
branch: master
specs:
rack-tracker (1.5.0)
activesupport (>= 3.0)
rack (>= 1.4)
tilt (>= 1.4)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -460,6 +470,7 @@ DEPENDENCIES
pry-rails
puma (~> 3.7)
pundit
rack-tracker!
rails (~> 5.1.2)
rails_12factor
redcarpet
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def current_user
return unless cookies[:auth_token]
@current_user ||= User.includes(:organisation)
.find_by(auth_token: cookies[:auth_token])
session[:user_id] = @current_user.id
@current_user
end

def load_recipient
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/eligibilities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def create
params[:mixpanel_eligibility_tracking] = true
@recipient.update_funds_checked!(@proposal.eligibility)
Assessment.analyse_and_update!(Fund.active, @proposal) # TODO: refactor
track_quiz_completion(@fund)
redirect_to proposal_fund_path(@proposal, @fund)
end
end
Expand Down Expand Up @@ -76,4 +77,16 @@ def update_eligibility_params
end
@proposal.save
end

def track_quiz_completion(fund)
tracker do |t|
t.google_analytics(
:send,
type: 'event',
category: 'eligibility-quiz',
action: 'submit-complete',
label: fund.slug
)
end
end
end
8 changes: 8 additions & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ document.addEventListener('turbolinks:before-visit', (e) => {
window.location = e.data.url
}
})

// Utility
window.trackOutboundLink = (url) => {
window.ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': () => { window.open(url) }
})
}
9 changes: 6 additions & 3 deletions app/services/companies_house.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ def initialize(company_number)
end
end

# TODO: refactor
def lookup(org)
if @res
data = @res['primaryTopic']

org.name = data['CompanyName'].titleize unless org.charity_number.present?
org.country = { 'United Kingdom' => 'GB' }[data['CountryOfOrigin']]
country = { 'United Kingdom' => 'GB' }[data['CountryOfOrigin']]

org.name = data['CompanyName'].titleize unless org.charity_number.present?
org.country = country if country
org.postal_code = data['RegAddress'].try(:[], 'Postcode') unless org.postal_code.present?
org.company_name = data['CompanyName'].titleize
org.company_status = data['CompanyStatus']
Expand All @@ -29,7 +32,7 @@ def lookup(org)
org.company_sic = data['SICCodes'].try(:[], 'SicText')

org.registered_on = data['IncorporationDate'] || data['RegistrationDate']
org.operating_for = operating_for_value(org.registered_on)
org.operating_for = operating_for_value(org.registered_on) if org.registered_on

if data['CompanyCategory'] == 'Community Interest Company'
org.org_type = 5
Expand Down
21 changes: 0 additions & 21 deletions app/views/shared/_head.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,6 @@
})(window,document.documentElement,'async-hide','dataLayer',4000,
{'GTM-TTGSBSF':true});

-# Google Analytics
:javascript
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-30021098-2', 'auto');
ga('require', 'linkid', 'linkid.js');
ga('require', 'GTM-TTGSBSF');
ga('send', 'pageview');

var trackOutboundLink = function (url) {
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': function () { window.open(url); }
});
};

-# Google Tag Manager
:javascript
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
Expand All @@ -59,8 +40,6 @@

- if logged_in?
= intercom_script_tag(email: @current_user.email, name: @current_user.full_name)
:javascript
ga("set", "userId", "#{@current_user.id}");

-# Mixpanel
:javascript
Expand Down
9 changes: 9 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

config.middleware.use(Rack::Tracker) do
handler :google_analytics, {
tracker: 'UA-30021098-2',
enhanced_link_attribution: true,
user_id: ->(env) { env['rack.session']['user_id'] },
optimize: 'GTM-TTGSBSF'
}
end
end

0 comments on commit 547f2aa

Please sign in to comment.