<commit_before># This file should be required as soon a possible to allow for
# early event tracking.

window.GaEvents = {}

class GaEvents.Event
  adapter: null
  @list: []
  @may_flush: false
  @header_key: "X-GA-Events"
  @html_key: "ga-events"
  klass: @

  # Decompose a event-string (ruby side) into an event object.
  @from_string: (string) ->
    $.map string.split("$"), (part) =>
      [category, action, label, value] = part.split "|"
      new @(category, action, label, value)

  @from_dom: ->
    dom_events = $("div[data-#{@html_key}]").data @html_key
    @from_string dom_events if dom_events?

  # Events should not be send to an adapter unless the DOM has finished loading.
  @flush: ->
    if @list.length > 0 and @may_flush
      $.map @list, (event) -> event.push_to_adapter()
      @list = []

  # Add all events to a queue to flush them later
  constructor: (@category = "-", @action = "-", @label = "-", @value = 1) ->
    @klass.list.push @
    @klass.flush()

  to_hash: ->
    # Category, action and label must be of type string.
    action: "#{@action}"
    category: "#{@category}"
    label: "#{@label}"
    # Value has to be a positive integer or defaults to 1
    value: @to_positive_integer(@value)

  to_positive_integer: (n) ->
    if isFinite(n) and parseInt(n) >= 0 then parseInt n else 1

  # https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide#SettingUpEventTracking
  push_to_adapter: -> @klass.adapter().push @to_hash()

  jQuery =>
    @may_flush = true
    @flush()

    process_xhr = (xhr) =>
      xhr_events = xhr.getResponseHeader @header_key
      @from_string xhr_events if xhr_events?

    $(document).ajaxComplete((_, xhr) -> process_xhr(xhr))
    $(document).on "turbolinks:request-end", (event) ->
      xhr = event.originalEvent.data.xhr
      process_xhr(xhr)
<commit_msg>#28805: Ensure Tracking-Values does not contain any umlauts<commit_after># This file should be required as soon a possible to allow for
# early event tracking.

window.GaEvents = {}

class GaEvents.Event
  adapter: null
  @list: []
  @may_flush: false
  @header_key: "X-GA-Events"
  @html_key: "ga-events"
  klass: @

  # Decompose a event-string (ruby side) into an event object.
  @from_string: (string) ->
    $.map string.split("$"), (part) =>
      [category, action, label, value] = part.split "|"
      new @(category, action, label, value)

  @from_dom: ->
    dom_events = $("div[data-#{@html_key}]").data @html_key
    @from_string dom_events if dom_events?

  # Events should not be send to an adapter unless the DOM has finished loading.
  @flush: ->
    if @list.length > 0 and @may_flush
      $.map @list, (event) -> event.push_to_adapter()
      @list = []

  # Add all events to a queue to flush them later
  constructor: (@category = "-", @action = "-", @label = "-", @value = 1) ->
    @klass.list.push @
    @klass.flush()

  escape: (str) ->
    return unless str
    "#{str}".replace(/ä/g, "ae")
            .replace(/ö/g, "oe")
            .replace(/ü/g, "ue")
            .replace(/Ä/g, "Ae")
            .replace(/Ö/g, "Oe")
            .replace(/Ü/g, "Ue")
            .replace(/ß/g, "ss")

  to_hash: ->
    # Category, action and label must be escaped and of type string.
    action: @escape(@action)
    category: @escape(@category)
    label: @escape(@label)
    # Value has to be a positive integer or defaults to 1
    value: @to_positive_integer(@value)

  to_positive_integer: (n) ->
    if isFinite(n) and parseInt(n) >= 0 then parseInt n else 1

  # https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide#SettingUpEventTracking
  push_to_adapter: -> @klass.adapter().push @to_hash()

  jQuery =>
    @may_flush = true
    @flush()

    process_xhr = (xhr) =>
      xhr_events = xhr.getResponseHeader @header_key
      @from_string xhr_events if xhr_events?

    $(document).ajaxComplete((_, xhr) -> process_xhr(xhr))
    $(document).on "turbolinks:request-end", (event) ->
      xhr = event.originalEvent.data.xhr
      process_xhr(xhr)

{'fraction_non_alphanumeric': 0.14700812607732086, 'fraction_numerical': 0.0036936715094804235, 'mean_word_length': 3.045816733067729, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3508457', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1379, 'n_words': 370}