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

Version Path
govuk_publishing_components-25.7.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.6.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.5.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.4.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.3.1 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.3.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.2.3 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.2.2 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.2.1 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.2.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.1.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-25.0.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-24.21.1 app/assets/javascripts/govuk_publishing_components/lib/select.js
govuk_publishing_components-24.21.0 app/assets/javascripts/govuk_publishing_components/lib/select.js
govuk_publishing_components-24.20.0 app/assets/javascripts/govuk_publishing_components/lib/select.js
govuk_publishing_components-24.19.0 app/assets/javascripts/govuk_publishing_components/lib/select.js
govuk_publishing_components-24.18.5 app/assets/javascripts/govuk_publishing_components/lib/select.js
govuk_publishing_components-24.18.4 app/assets/javascripts/govuk_publishing_components/lib/select.js
govuk_publishing_components-24.18.3 app/assets/javascripts/govuk_publishing_components/lib/select.js
govuk_publishing_components-24.18.2 app/assets/javascripts/govuk_publishing_components/lib/select.js