簡體   English   中英

GTM - 滾動的退出意圖 - 自定義 HTML

[英]GTM - Exit Intent for scroll - Custom HTML

我正在尋找一些幫助,以便在我的網站上為退出意圖編寫 function 編碼,而不是經典的 function,就像有人將 cursor 從退出意圖移動到快速滾動的網站一樣。 甚至可能嗎?

我找到了這樣的代碼,但它對我不起作用。

    <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>

我收到此錯誤消息:

第 2 行,字符 12 處的錯誤:此語言功能僅支持 ECMASCRIPT_2015 或更好的模式:箭頭 function.JavaScript 編譯器錯誤User.Z4D236D9A2D102C5FE6AD1CZDA4 InjectBEC500

第 5 行,字符 15 處的錯誤:此語言功能僅支持 ECMASCRIPT_2015 模式或更好的模式:箭頭 function.JavaScript 編譯器錯誤User.Z4D236D9A2D102C5FE6AD1CZDA4 InjectBEC500

第 7 行,字符 14 處的錯誤:此語言功能僅支持 ECMASCRIPT_2015 或更好的模式:箭頭 function。

關於如何實施的任何想法?

您在 Google 跟蹤代碼管理器中使用不允許的箭頭 function。

需要改成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>

但是當我測試這段代碼時。

會有錯誤: userengage is not defined

你能追溯這段代碼的來源嗎? 你可能會錯過其中的一部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM