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