Search code examples
javascriptvue.jsgoogle-tag-manager

How to fix "This language feature is only supported for ECMASCRIPT6 mode" in GTM?


I try to use some js code in GTM, but have this error. an error occurs in this line

window.sbHooks.addAction('sbCoreState::CreateBets/success', (data, response) => {

where i used custom vue js hook. how i can fix it?

<script>
if (typeof window.sbHooks === 'object') {
  // отправим данные о достижении цели (размещение ставки/прогноза) в Яндекс Метрику
  window.sbHooks.addAction('sbCoreState::CreateBets/success', (data, response) => {
    //data.express_bet - сумма экспресса, если это значение есть  - то ставка экспресс
    //data.express_tip - текст экспресса
    //добавлен экспресс с прогнозом или без
    if (
      typeof data.express_bet !== 'undefined' &&
      typeof response.body.ids !== 'undefined' &&
      Array.isArray(response.body.ids) &&
      response.body.ids.length > 0
    ) {
      if (typeof yaCounter47035968 != 'undefined') {
        yaCounter47035968.reachGoal('AddTipExpress');
        if (data.express_tip.length > 0) {
          yaCounter47035968.reachGoal('AddReviews');
        }
      }
    }

    // Если это несколько ставок, то переберем их и посмотрим есть ли текст
    if (
      typeof data.express_bet == 'undefined' &&
      data.bets.length > 0
    ) {
      for (var i = 0; i <= data.bets.length - 1; i++) {
        var tip_text = data.bets[i].tip_text;
        if (typeof yaCounter47035968 != 'undefined') {
          yaCounter47035968.reachGoal('AddTipOrdinary');
          if (typeof tip_text !== 'undefined') {
            yaCounter47035968.reachGoal('AddReviews');
          }
        }
      }
    }
  });
}
</script>

Solution

  • Convert the arrow function to a function function.

      window.sbHooks.addAction('sbCoreState::CreateBets/success', function(data, response) {
    // the rest stays the same