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-28.5.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-28.4.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-28.3.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-28.2.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-28.1.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-28.0.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.20.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.19.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.18.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.17.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.16.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.15.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.14.2 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.14.1 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.14.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.13.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.12.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.11.0 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.10.5 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
govuk_publishing_components-27.10.4 app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js