Sha256: 36b7e69926c44d8fb494805f44b812dfef08db50538747f30c0703f8fe36bde2
Contents?: true
Size: 1.86 KB
Versions: 143
Compression:
Stored size: 1.86 KB
Contents
window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function TrackSelectChange () { } TrackSelectChange.prototype.start = function ($module) { this.$module = $module[0] this.$module.trackChange = this.trackChange.bind(this) this.$module.fireTrackingChange = this.fireTrackingChange.bind(this) this.$module.addEventListener('change', this.trackChange) } TrackSelectChange.prototype.trackChange = function () { var selectedOption = this.options[this.selectedIndex] if (selectedOption.hasAttribute('data-track-category') && selectedOption.hasAttribute('data-track-action')) { this.fireTrackingChange(selectedOption) } } TrackSelectChange.prototype.fireTrackingChange = function (selectedOption) { var options = { transport: 'beacon' } var category = selectedOption.getAttribute('data-track-category') var action = selectedOption.getAttribute('data-track-action') var label = selectedOption.getAttribute('data-track-label') var value = selectedOption.getAttribute('data-track-value') var dimension = selectedOption.getAttribute('data-track-dimension') var dimensionIndex = selectedOption.getAttribute('data-track-dimension-index') var extraOptions = selectedOption.getAttribute('data-track-options') if (label) { options.label = label } if (value) { options.value = value } if (dimension && dimensionIndex) { options['dimension' + dimensionIndex] = dimension } if (extraOptions) { extraOptions = JSON.parse(extraOptions) for (var k in extraOptions) options[k] = extraOptions[k] } if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) { window.GOVUK.analytics.trackEvent(category, action, options) } } Modules.TrackSelectChange = TrackSelectChange })(window.GOVUK.Modules)
Version data entries
143 entries across 143 versions & 1 rubygems