You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Tag Manager中JavaScript编译错误:Parse error. primary expression expected求助

Troubleshooting the "Primary Expression Expected" Error in GTM Custom HTML Tag (Line 146)

Hey there! That parse error on the final line of your GTM custom HTML tag is super common, and it almost always boils down to unfinished or mismatched syntax from earlier in your code that the parser finally chokes on at the end. Let’s walk through the most likely culprits:

  • Unclosed parentheses, brackets, or curly braces
    This is the #1 offender. If you opened a function with function myTracking() {, a conditional with if (userLoggedIn) {, an array with var ids = [1, 2,, or even a simple function call like dataLayer.push({, but never added the closing }, ], or ), the parser will keep looking for that closure until the end of the code—throwing this error on line 146 because it never found it.

  • Unterminated string literals
    Forgot to close a quote? For example, if you have something like var eventLabel = "Checkout started (missing the closing "), the parser will treat every subsequent line as part of that string until it hits the end of the tag, triggering the error when it realizes it never found the closing quote.

  • Incomplete statements left hanging
    If a line before the last one ends with an operator that expects more input—like var total = cartValue + or if (pageType ===—the parser will look to the next line (your final line) for the rest of the expression. If line 146 doesn’t provide that (or is empty), it’ll throw this "primary expression expected" error because it’s missing the value/condition it needs.

  • Stray or misplaced syntax characters
    Sometimes a random extra comma, semicolon, or curly brace on the final line can confuse the parser. For example, if line 146 is just a lone } with no matching opening { earlier, or a trailing comma after the last item in an object, the parser won’t recognize a valid expression here.

Quick Fix Tips

  1. Start from line 146 and work backwards—scan for any unclosed symbols or unfinished statements.
  2. Copy your entire tag code into a basic JavaScript syntax checker to highlight mismatched closures or unclosed strings instantly.
  3. Comment out large chunks of your code one by one, publish a test version, and see when the error disappears—this will narrow down exactly where the broken syntax lives.

内容的提问来源于stack exchange,提问作者Charlie Howes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:22:01