Javascript 将自定义html添加到Google标记管理器时出错

Javascript 将自定义html添加到Google标记管理器时出错,javascript,google-tag-manager,Javascript,Google Tag Manager,我不是很喜欢JS,你能告诉我这段代码有什么问题吗?我试图添加此内容,但出现了一个错误“第74行错误,字符3:分析错误”。)“预期”。我真的不知道该修什么 <script id="gtm-scroll-tracking" type="text/javascript"> ; (function (document, window, config) { // Browser dependencies, script fails silently if

我不是很喜欢JS,你能告诉我这段代码有什么问题吗?我试图添加此内容,但出现了一个错误“第74行错误,字符3:分析错误”。)“预期”。我真的不知道该修什么

<script id="gtm-scroll-tracking" type="text/javascript">
    ; (function (document, window, config) {
        // Browser dependencies, script fails silently
        if (!document.querySelector || !document.body.getBoundingClientRect) {
            return false;
        }
        // Get our dataLayer ready, in case we're not in GTM or we've got a special name
        var dataLayerName = config.dataLayerName || 'dataLayer';
        var dataLayer = window[dataLayerName] || (window[dataLayerName] = []);
        var cache = {};
        // Initialize our distances, for later
        config.distances = config.distances || {};
        checkDepth();
        addEvent(window, 'scroll', throttle(checkDepth, 500));
        function getMarks(_docHeight, _offset) {
            var marks = {};
            var percents = [];
            var pixels = []
            if (config.distances.percentages) {
                if (config.distances.percentages.each) {
                    percents = percents.concat(config.distances.percentages.each);
                }
                if (config.distances.percentages.every) {
                    var _every = every_(config.distances.percentages.every, 100);
                    percents = percents.concat(_every);
                }
            }
            if (config.distances.pixels) {
                if (config.distances.pixels.each) {
                    pixels = pixels.concat(config.distances.pixels.each);
                }
                if (config.distances.pixels.every) {
                    var _every = every_(config.distances.pixels.every, _docHeight);
                    pixels = pixels.concat(_every);
                }
            }
            marks = addMarks_(marks, percents, '%', _docHeight, _offset);
            marks = addMarks_(marks, pixels, 'px', _docHeight, _offset);
            return marks;
        }
        function addMarks_(marks, points, symbol, _docHeight, _offset) {
            var i;
            for (i = 0; i < points.length; i++) {
                var _point = parseInt(points[i], 10);
                var height = symbol !== '%' ? _point + _offset : _docHeight *
                    (_point / 100) + _offset;
                var mark = _point + symbol;
                if (height <= _docHeight + _offset) { marks[mark] = height; }
            }
            return marks;
        }
        function every_(n, total) {
            var n = parseInt(n, 10);
            var _num = total / n;
            var arr = [];
            for (i = 1; i < _num + 1; i++) { arr.push(i * n); }
            return arr;
        }
        function checkDepth() {
            var _bottom = parseBorder_(config.bottom);
            var _top = parseBorder_(config.top);
            var height = docHeight(_bottom, _top);
            var marks = getMarks(height, (_top || 0));
            var _curr = currentPosition();
            for (key in marks) {
                if (_curr > marks[key] && !cache[key]) {
                    cache[key] = true;
                    fireAnalyticsEvent(key);
                }
            }
        }
        function fireAnalyticsEvent(distance) {
            dataLayer.push({
                'event': 'scrollTracking',
                'attributes': { 'distance': distance }
            });
        }
    }
    function parseBorder_(border) {
        if (typeof border === 'Number' || parseInt(border, 10)) {
            return parseInt(border, 10);
        }
        try {
            // If we have an element or a query selector, poll getBoundingClientRect
            var el = border.nodeType && border.nodeType === 1 ? border :
                document.querySelector(border);
            var docTop = document.body.getBoundingClientRect().top;
            var _elTop = Math.floor(el.getBoundingClientRect().top - docTop);
            return _elTop;
        } catch (e) { return void (0); }
    }
    // Adapted from
    https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY
    function currentPosition() {
        var supportPageOffset = window.pageXOffset !== undefined;
        var isCSS1Compat = ((document.compatMode || "") === "CSS1Compat");
        var currScrollTop = supportPageOffset ?
            window.pageYOffset :
            isCSS1Compat ?
                document.documentElement.scrollTop :
                document.body.scrollTop;
        return parseInt(currScrollTop, 10) + parseInt(viewportHeight(), 10);
    }
    function viewportHeight() {
        var elem = (document.compatMode === "CSS1Compat") ?
            document.documentElement :
            document.body;
        return elem.clientHeight;
    }
    function docHeight(_bottom, _top) {
        var body = document.body;
        var html = document.documentElement;
        var height = Math.max(body.scrollHeight, body.offsetHeight,
            html.clientHeight, html.scrollHeight, html.offsetHeight);
        if (_top) { height = height - _top; }
        if (_bottom) { height = _bottom - _top; }
        return height - 5;
    }
    /*
     * Throttle function borrowed from:
     * Underscore.js 1.5.2
     * http://underscorejs.org
     *
  (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative
  Reporters & Editors
     * Underscore may be freely distributed under the MIT license.
     */
    function throttle(func, wait) {
        var context, args, result;
        var timeout = null;
        var previous = 0;
        var later = function () {
            previous = new Date;
            timeout = null;
            result = func.apply(context, args);
        };
        return function () {
            var now = new Date;
            if (!previous) previous = now;
            var remaining = wait - (now - previous);
            context = this;
            args = arguments;
            if (remaining <= 0) {
                clearTimeout(timeout);
                timeout = null;
                previous = now;
                result = func.apply(context, args);
            } else if (!timeout) {
                timeout = setTimeout(later, remaining);
            }
            return result;
        };
    }
    // Cross-browser compliant event listener
    function addEvent(el, evt, fn) {
        if (el.addEventListener) { return el.addEventListener(evt, fn); }
        if (el.attachEvent) {
            return el.attachEvent('on' + evt, function (evt) {
                // Call the event to ensure uniform 'this' handling, pass it event
                fn.call(el, evt);
            });
        }
        if (typeof el['on' + evt] === 'undefined' || el['on' + evt] === null) {
            return el['on' + evt] = function (evt) {
                // Call the event to ensure uniform 'this' handling, pass it event
                fn.call(el, evt); \
            }
        }
    }
    })(document, window,
        {
            // False if you just use the default dataLayer variable, otherwise enter it here
            'dataLayerName': false,
            'distances': {
                // Configure percentages of page you'd like to see if users scroll past
                'percentages': {
                    'each': [10, 90],
                    'every': 25
                },
                // Configure for pixel measurements of page you'd like to see if users scroll past
                'pixels': {
                    'each': [],
                    'every': null
                }
            },
            // Accepts a number, DOM element, or query selector to determine the top of the scrolling area
            'top': null,
            // Accepts a number, DOM element, or query selector to determine the bottom of the scrolling area
            'bottom': null,
        });
</script>

; (功能(文档、窗口、配置){
//浏览器依赖项,脚本以静默方式失败
如果(!document.querySelector | |!document.body.getBoundingClientRect){
返回false;
}
//准备好我们的数据层,以防我们不在GTM中或我们有一个特殊的名称
var dataLayerName=config.dataLayerName | |‘dataLayer’;
var dataLayer=window[dataLayerName]| |(window[dataLayerName]=[]);
var cache={};
//初始化我们的距离,以便以后使用
config.distance=config.distance | |{};
检查深度();
addEvent(窗口,“滚动”,油门(检查深度,500));
函数getMarks(_docHeight,_offset){
var标记={};
风险值百分比=[];
变量像素=[]
if(配置距离百分比){
if(配置距离百分比各){
percents=percents.concat(配置距离百分比各);
}
if(配置距离百分比每){
var _every=every(config.distance.percentrates.every,100);
百分比=浓度百分比(_every);
}
}
if(config.distance.pixels){
if(配置距离像素数每个){
像素=像素.concat(配置距离.pixels.each);
}
if(config.distance.pixels.every){
var _every=every(config.distance.pixels.every,_docHeight);
像素=像素。concat(_every);
}
}
分数=增加分数(分数,百分比,'%',八分,偏移量);
marks=addMarks(标记,像素,'px','u八,'u偏移量);
返回标记;
}
功能添加标记(标记、点、符号、\u八、\u偏移){
var i;
对于(i=0;i如果(剩下的问题是您复制粘贴在自定义HTML标记中的代码/JavaScript的问题,基本上代码没有正确关闭函数。您的帖子中提供的代码片段使调试变得困难,因为它有许多问题,例如,结尾处的注释与//,不在同一行,可能是因为格式不同粘贴到帖子中时会显示滚动。您的网站是否使用jQuery?如果可以,您可以尝试实现此脚本,它也会为Google Tag Manager提供说明。这还将跟踪滚动深度。首先,请自行调试并缩小代码范围。对于