0

I'm looking for some help with coding a function for exit-intent on my website, but instead of classic function like someone moves a cursor away from website I'd like to implement a fast scroll up as a exit-intent. Is it even possible?

I found code like this but it doesn't work for me.

    <script>
setTimeout(() => {

  document.addEventListener("scroll", scrollSpeed);

}, 10000);





scrollSpeed = () => {

  lastPosition = window.scrollY;

  setTimeout(() => {

    newPosition = window.scrollY;

  }, 100);

  currentSpeed = newPosition - lastPosition;

  console.log(currentSpeed);



  if (currentSpeed > 160) {

userengage('event.exit-intent-mobile');

    document.removeEventListener("scroll", scrollSpeed);

  }

};
</script>

I'm getting this error message:

Error at line 2, character 12: This language feature is only supported for ECMASCRIPT_2015 mode or better: arrow function.JavaScript compiler errorUser.com - Exit Intent Mobile

Error at line 5, character 15: This language feature is only supported for ECMASCRIPT_2015 mode or better: arrow function.JavaScript compiler errorUser.com - Exit Intent Mobile

Error at line 7, character 14: This language feature is only supported for ECMASCRIPT_2015 mode or better: arrow function.

Any ideas on how to implement that?

Limbov
  • 1

1 Answers1

0

You are using arrow function in Google Tag Manager which is not allowed.

Need to change it into function(args){}

<script>
setTimeout(function(){

  document.addEventListener("scroll", scrollSpeed);

}, 10000);

var scrollSpeed = function(){

  lastPosition = window.scrollY;

  setTimeout(function(){

    newPosition = window.scrollY;

  }, 100);

  currentSpeed = newPosition - lastPosition;

  console.log(currentSpeed);



  if (currentSpeed > 160) {

    userengage('event.exit-intent-mobile');

    document.removeEventListener("scroll", scrollSpeed);

  }

};
</script>

But when I test this code.

There will be error : userengage is not defined

Can you track back where this code coming from. You might miss some piece of it.

darrelltw
  • 1,734
  • 1
  • 10
  • 21