I attempted to implement some JavaScript code in GTM, but encountered an error. The error occurs at this line
window.sbHooks.addAction('sbCoreState::CreateBets/success', (data, response) => {
where I utilized a custom Vue.js hook. How can I resolve this issue?
<script>
if (typeof window.sbHooks === 'object') {
// Send data about achieving the goal (placing bets/predictions) to Yandex Metrika
window.sbHooks.addAction('sbCoreState::CreateBets/success', (data, response) => {
//data.express_bet - amount of express bet, if this value exists - it's an express bet
//data.express_tip - express text
//added express with prediction or without
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 there are multiple bets, iterate through them and check for text
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>