<commit_before>import MatomoTracker from '@datapunt/matomo-tracker-js'
// eslint-disable-next-line import/no-cycle
import trackEvents from './trackEvents'
// eslint-disable-next-line import/no-cycle
import trackViews from './trackViews'
import { authCustomDimensions, viewCustomDimensions } from './customDimensions'
import { MATOMO_CONFIG } from './constants'

// Execute Matomo actions
const matomoMiddleware = ({ getState }) => next => action => {
  const nextAction = action

  // Initialize connection with Matomo
  const MatomoInstance = new MatomoTracker({
    urlBase: MATOMO_CONFIG.BASE_URL,
    siteId: MATOMO_CONFIG[process.env.NODE_ENV].SITE_ID,
  })

  const actionsToMatomo = []
  if (trackViews[action.type]) {
    actionsToMatomo.push(trackViews[action.type])
  }
  if (trackEvents[action.type]) {
    actionsToMatomo.push(trackEvents[action.type])
  }

  if (actionsToMatomo.length) {
    const { firstAction, location, query, tracking } = action.meta || {}
    const state = getState()

    const { href } = window.location
    const { title } = window.document

    if (tracking || location) {
      const customDimensions = [
        ...authCustomDimensions(state),
        ...viewCustomDimensions(query, state),
      ]

      actionsToMatomo.forEach(matomoAction => {
        MatomoInstance.track({
          data: matomoAction({
            tracking,
            firstAction,
            query,
            state,
            title,
            href,
          }),
          href,
          title,
          customDimensions,
        })<commit_msg>Send old page title to matomo<commit_after>import MatomoTracker from '@datapunt/matomo-tracker-js'
// eslint-disable-next-line import/no-cycle
import trackEvents from './trackEvents'
// eslint-disable-next-line import/no-cycle
import trackViews from './trackViews'
import { authCustomDimensions, viewCustomDimensions } from './customDimensions'
import { MATOMO_CONFIG } from './constants'

// Execute Matomo actions
const matomoMiddleware = ({ getState }) => next => action => {
  const nextAction = action

  // Initialize connection with Matomo
  const MatomoInstance = new MatomoTracker({
    urlBase: MATOMO_CONFIG.BASE_URL,
    siteId: MATOMO_CONFIG[process.env.NODE_ENV].SITE_ID,
  })

  const actionsToMatomo = []
  if (trackViews[action.type]) {
    actionsToMatomo.push(trackViews[action.type])
  }
  if (trackEvents[action.type]) {
    actionsToMatomo.push(trackEvents[action.type])
  }

  if (actionsToMatomo.length) {
    const { firstAction, location, query, tracking } = action.meta || {}
    const state = getState()

    const { href } = window.location
    const { title } = window.document

    // Matomo uses the document title for tracking pageviews.
    // We have to convert the title to the 'old' format (Dataportaal) in order to keep the existing data
    const titleForMatomo = title.replace('Data en informatie | Amsterdam', 'Dataportaal')

    if (tracking || location) {
      const customDimensions = [
        ...authCustomDimensions(state),
        ...viewCustomDimensions(query, state),
      ]

      actionsToMatomo.forEach(matomoAction => {
        MatomoInstance.track({
          data: matomoAction({
            tracking,
            firstAction,
            query,
            state,
            title: titleForMatomo,
            href,
          }),
          href,
          title: titleForMatomo,
          customDimensions,
        })
{'fraction_non_alphanumeric': 0.10875870069605569, 'fraction_numerical': 0.0, 'mean_word_length': 2.773522975929978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '5317835', 'n_tokens_mistral': 998, 'n_tokens_neox': 979, 'n_words': 228}