Javascript 干扰 GTM

Javascript interferring with GTM

我发现手风琴脚本正在干扰设置为跟踪 PDF 下载的 GTM。手风琴脚本打开并折叠下载链接列表。它实际上是 2 个脚本;第一个启动 ddaccordion.js,第二个设置参数。

它们在头部,然后我在页面末尾尝试了它们 - 没有区别。如果我删除一个或另一个脚本,GTM 将开始跟踪下载。所有其他 PDF 下载在整个站点中正常跟踪。

这是 2 个脚本:

    <script type="text/javascript" src="js/ddaccordion.js">

    /*••••••••••••••••••••••••••••••••••••••••••••••
    • Accordion Content script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    • Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
    • This notice must stay intact for legal use
    ••••••••••••••••••••••••••••••••••••••••••••••*/

    </script>

    <script type="text/javascript">


        ddaccordion.init({
                headerclass: "expandable", //Shared CSS class name of headers group that are expandable
                contentclass: "categoryitems", //Shared CSS class name of contents group
                revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
                mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
                collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
                defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
                onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
                animatedefault: true, //Should contents open by default be animated into view?
                persiststate: false, //persist state of opened contents within browser session?
                toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
                togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
                animatespeed: "2500", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
                oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
                    //do nothing
                },
                onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
                document.getElementById('main-content').style.height=document.getElementById('side-bar').style.height=document.getElementById('photo-bar').style.height=document.getElementById('anchor').offsetTop+'px';;

                //do nothing   "side-bar", "main-content", "photo-bar"
                }
            })


    </script>

有没有办法在不丢失手风琴功能的情况下解决这个问题?

解决方案是将 ddaccordion.js 脚本(出现一次)中的 "return false" 替换为 "e.preventDefault()"。感谢@Eike-Pierstorff 的解决方案。