Google Tag Manager - Primary Expression Expected

不羁岁月 提交于 2021-02-11 14:14:27

问题


Following is my code:

<script>
    <button type = "button"
    onclick="sce.event('mw_button_click', {
    ...});>
    </button>
</script>

And when i try to enter the debug mode in Google Tag Manager I have an error:

Error in line 2 character 4: Pare error. Primary expression expected.

Does anyone know how to fix it and can help me?


回答1:


If you use the button tag inside the script tag it doesn't work in GTM .Instead you should use Javascript or Jquery like I mentioned below

The below is an example from https://www.w3schools.com/jsref/event_onclick.asp . Hope this helps

// Get the button, and when the user clicks on it, execute myFunction document.getElementById("myBtn").onclick = function() {myFunction()};

/* myFunction toggles between adding and removing the show class, which is used to hide and show the dropdown content */

function myFunction() {
  document.getElementById("myDropdown").classList.toggle("show");
}



回答2:


I think you need to put your onclick event into a function of its own.

Like this:

<script>
  function myEvent() {
    ...do code
  }

  <button 
    type = "button"
    onclick="myEvent('mw_button_click')">
  </button>
</script>


来源:https://stackoverflow.com/questions/52198604/google-tag-manager-primary-expression-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!