[{"data":1,"prerenderedAt":396},["ShallowReactive",2],{"rule-variable-cookie-access":3},{"id":4,"title":5,"body":6,"breadcrumb":361,"coderail":367,"dateModified":385,"datePublished":385,"description":386,"extension":387,"meta":388,"navigation":389,"next":385,"path":390,"prev":385,"schemaType":391,"seo":392,"stem":393,"wide":394,"__hash__":395},"docs\u002Frules\u002Fvariable-cookie-access.md","Direct document.cookie access",{"type":7,"value":8,"toc":353},"minimark",[9,16,58,63,81,85,91,95,225,229,260,264,321,325,349],[10,11,12],"p",{},[13,14,15],"strong",{},"Summary",[17,18,19,30,40,46,52],"ul",{},[20,21,22,25,26],"li",{},[13,23,24],{},"rule_id"," — ",[27,28,29],"code",{},"variable-cookie-access",[20,31,32,35,36,39],{},[13,33,34],{},"purpose"," — Detect Custom JavaScript variables that read ",[27,37,38],{},"document.cookie"," directly",[20,41,42,45],{},[13,43,44],{},"effect"," — Manual cookie parsing is fragile and bypasses GTM's consent-aware cookie variable type",[20,47,48,51],{},[13,49,50],{},"layer"," — container",[20,53,54,57],{},[13,55,56],{},"reversibility"," — non-destructive",[59,60,62],"h2",{"id":61},"what-fires-this","What fires this",[10,64,65,66,69,70,73,74,77,78,80],{},"The rule filters ",[27,67,68],{},"data.variables"," for entries where ",[27,71,72],{},"type === 'jsm'"," (Custom JavaScript variable). For each match, it reads ",[27,75,76],{},"v.parameters.javascript"," and tests for ",[27,79,38],{}," (case-insensitive regex). Any variable containing that pattern is flagged. The rule returns one issue listing all affected variables by ID and name. Variables of other types are not checked.",[59,82,84],{"id":83},"why-it-matters","Why it matters",[10,86,87,88,90],{},"GTM (Google Tag Manager) provides a built-in First-Party Cookie variable type. It reads a named cookie without requiring manual string parsing. Custom JavaScript variables that call ",[27,89,38],{}," must parse the raw cookie string themselves — a pattern prone to edge cases with missing cookies, special characters, and encoding. The built-in type also integrates with GTM's consent framework. When consent blocks cookie access, the built-in variable handles that gracefully. A Custom JavaScript variable must replicate that handling manually or silently misbehave.",[59,92,94],{"id":93},"example","Before \u002F after",[96,97,98,214],"compare",{},[99,100,102],"compare-col",{"label":101},"Before — flagged",[103,104,109],"pre",{"className":105,"code":106,"language":107,"meta":108,"style":108},"language-js shiki shiki-themes github-light github-dark","\u002F\u002F Custom JavaScript variable — reads raw cookie string\nfunction() {\n  var match = document.cookie.match(\u002Fsession_id=([^;]+)\u002F)\n  return match ? match[1] : undefined\n}\n","js","",[27,110,111,120,131,182,208],{"__ignoreMap":108},[112,113,116],"span",{"class":114,"line":115},"line",1,[112,117,119],{"class":118},"sJ8bj","\u002F\u002F Custom JavaScript variable — reads raw cookie string\n",[112,121,123,127],{"class":114,"line":122},2,[112,124,126],{"class":125},"szBVR","function",[112,128,130],{"class":129},"sVt8B","() {\n",[112,132,134,137,140,143,146,150,153,157,161,165,168,171,174,177,179],{"class":114,"line":133},3,[112,135,136],{"class":125},"  var",[112,138,139],{"class":129}," match ",[112,141,142],{"class":125},"=",[112,144,145],{"class":129}," document.cookie.",[112,147,149],{"class":148},"sScJk","match",[112,151,152],{"class":129},"(",[112,154,156],{"class":155},"sZZnC","\u002F",[112,158,160],{"class":159},"sA_wV","session_id=(",[112,162,164],{"class":163},"sj4cs","[",[112,166,167],{"class":125},"^",[112,169,170],{"class":163},";]",[112,172,173],{"class":125},"+",[112,175,176],{"class":159},")",[112,178,156],{"class":155},[112,180,181],{"class":129},")\n",[112,183,185,188,190,193,196,199,202,205],{"class":114,"line":184},4,[112,186,187],{"class":125},"  return",[112,189,139],{"class":129},[112,191,192],{"class":125},"?",[112,194,195],{"class":129}," match[",[112,197,198],{"class":163},"1",[112,200,201],{"class":129},"] ",[112,203,204],{"class":125},":",[112,206,207],{"class":163}," undefined\n",[112,209,211],{"class":114,"line":210},5,[112,212,213],{"class":129},"}\n",[99,215,217],{"label":216},"After — fixed",[103,218,223],{"className":219,"code":221,"language":222,"meta":108},[220],"language-text","GTM variable type: 1st Party Cookie\nCookie Name: session_id\n\nNo JavaScript required. GTM parses the cookie\nand handles consent-blocked access automatically.\n","text",[27,224,221],{"__ignoreMap":108},[59,226,228],{"id":227},"remediation","Remediation",[230,231,232,235,241,248,251,254,257],"ol",{},[20,233,234],{},"Open the flagged Custom JavaScript variable in GTM.",[20,236,237,238,240],{},"Identify which cookie name(s) the code reads from ",[27,239,38],{},".",[20,242,243,244,247],{},"Create a new GTM variable using the built-in ",[13,245,246],{},"1st Party Cookie"," type, setting the cookie name field to the identified cookie.",[20,249,250],{},"Replace every reference to the Custom JavaScript variable — in tags, triggers, and other variables — with the new First-Party Cookie variable.",[20,252,253],{},"Verify the replacement in GTM Preview mode and confirm the correct value resolves.",[20,255,256],{},"Delete or pause the Custom JavaScript variable once the transition is confirmed.",[20,258,259],{},"Publish the container.",[59,261,263],{"id":262},"metadata","Metadata",[265,266,269,270,275,269,279,283,269,286,290,269,293,296,269,299,303,269,305,309,269,315,318],"dl",{"className":267},[268],"spec-list","\n  ",[271,272,274],"dt",{"id":273},"severity","Severity",[276,277,278],"dd",{},"low",[271,280,282],{"id":281},"tier","Tier",[276,284,285],{},"info",[271,287,289],{"id":288},"category","Category",[276,291,292],{},"quality",[271,294,295],{"id":50},"Layer",[276,297,298],{},"container",[271,300,302],{"id":301},"version","Version",[276,304,198],{},[271,306,308],{"id":307},"effort","Effort",[276,310,311,314],{},[27,312,313],{},"15min"," (about 15 minutes)",[271,316,317],{"id":56},"Reversibility",[276,319,320],{},"non-destructive",[59,322,324],{"id":323},"see-also","See also",[17,326,327,335,342],{},[20,328,329,334],{},[330,331,333],"a",{"href":332},"\u002Fcategories\u002Fquality\u002F","Quality rules"," — other rules in this category",[20,336,337,341],{},[330,338,340],{"href":339},"\u002Fhealth-score\u002F","Health score"," — how this rule contributes to the score",[20,343,344,348],{},[330,345,347],{"href":346},"\u002Frules\u002F","Rules catalog"," — browse all rules",[350,351,352],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sA_wV, html code.shiki .sA_wV{--shiki-default:#032F62;--shiki-dark:#DBEDFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":108,"searchDepth":122,"depth":122,"links":354},[355,356,357,358,359,360],{"id":61,"depth":122,"text":62},{"id":83,"depth":122,"text":84},{"id":93,"depth":122,"text":94},{"id":227,"depth":122,"text":228},{"id":262,"depth":122,"text":263},{"id":323,"depth":122,"text":324},[362,364,366],{"label":363,"href":156},"API Reference",{"label":365,"href":346},"Rules",{"label":29},{"cards":368,"onpage":379},[369],{"title":370,"tabs":371},"Evaluate",[372,376],{"label":373,"language":374,"code":375},"cURL","bash","curl https:\u002F\u002Fdeveloper.tagmanifest.com\u002Fv1\u002Fevaluate-rule \\\n  -H \"Authorization: Bearer $TM_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"rule_id\":\"variable-cookie-access\",\"url\":\"https:\u002F\u002Fexample.com\"}'\n",{"label":377,"language":222,"code":378},"MCP","User: Run variable-cookie-access on https:\u002F\u002Fexample.com\n\n# Tool call\n{\n  \"tool\": \"evaluate_rule\",\n  \"arguments\": {\n    \"rule_id\": \"variable-cookie-access\",\n    \"url\": \"https:\u002F\u002Fexample.com\"\n  }\n}\n",[380,381,382,383,384],{"id":61,"label":62},{"id":83,"label":84},{"id":93,"label":94},{"id":227,"label":228},{"id":262,"label":263},null,"Custom JavaScript variable accesses document.cookie directly instead of using GTM's built-in Cookie variable type.","md",{},true,"\u002Frules\u002Fvariable-cookie-access","TechArticle",{"title":5,"description":386},"rules\u002Fvariable-cookie-access",false,"k2qxBkDKQhf8PGdee70hHmnHekjJBtzy1vSxckkwCZg",1796069484398]