Skip to content

Commit

Permalink
Merge pull request #1114 from alphagov/enable-cross-domain-event-trac…
Browse files Browse the repository at this point in the history
…king

Enable cross domain event tracking for radio buttons
  • Loading branch information
steventux authored Oct 4, 2018
2 parents d025fbd + 84ec76f commit 716ff38
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ gem 'uglifier', '>= 1.3.0'
gem 'gds-api-adapters', '~> 53.1'
gem 'govuk_ab_testing', '~> 2.4'
gem 'govuk_app_config', '~> 1.9'
gem 'govuk_frontend_toolkit', '~> 8.0'
gem 'govuk_frontend_toolkit', '~> 8.1.0'
gem 'govuk_publishing_components', '~> 11.1.0'
gem 'plek', '~> 2.1'
gem 'slimmer', '~> 13.0'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ GEM
sentry-raven (~> 2.7.1)
statsd-ruby (~> 1.4.0)
unicorn (~> 5.4.0)
govuk_frontend_toolkit (8.0.0)
govuk_frontend_toolkit (8.1.0)
railties (>= 3.1.0)
sass (>= 3.2.0)
govuk_publishing_components (11.1.0)
Expand Down Expand Up @@ -366,7 +366,7 @@ DEPENDENCIES
govuk-lint
govuk_ab_testing (~> 2.4)
govuk_app_config (~> 1.9)
govuk_frontend_toolkit (~> 8.0)
govuk_frontend_toolkit (~> 8.1.0)
govuk_publishing_components (~> 11.1.0)
govuk_schemas (~> 3.2)
htmlentities (~> 4.3)
Expand Down
8 changes: 5 additions & 3 deletions app/assets/javascripts/modules/track-radio-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
checkedValue = 'submitted-without-choosing'
}
if (typeof element.attr('data-tracking-code') !== 'undefined') {
addCrossDomainTracking(element, $checkedOption)
addCrossDomainTracking(element, $checkedOption, options)
}
GOVUK.analytics.trackEvent('Radio button chosen', checkedValue + (withHint ? '-with-hint' : ''), options)
})
Expand Down Expand Up @@ -56,13 +56,15 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
}
}

function addCrossDomainTracking(element, $checkedOption) {
function addCrossDomainTracking(element, $checkedOption, options) {
var code = element.attr('data-tracking-code')
var name = element.attr('data-tracking-name')
var url = $checkedOption.attr('data-tracking-url')
var hostname = $('<a>').prop('href', url).prop('hostname')

GOVUK.analytics.addLinkedTrackerDomain(code, name, hostname)
GOVUK.analytics.addLinkedTrackerDomain(code, name, hostname, false)
options['trackerName'] = name
GOVUK.analytics.trackEvent('Radio button chosen', $checkedOption.val(), options)
}
}
})(window, window.GOVUK);

0 comments on commit 716ff38

Please sign in to comment.