瀏覽代碼

Fixed issue with exclusions

bmallred 11 年之前
父節點
當前提交
2f4caad54f
共有 1 個文件被更改,包括 28 次插入18 次删除
  1. 28 18
      jquery-analytics.js

+ 28 - 18
jquery-analytics.js

@ -49,6 +49,23 @@ String.prototype.endsWith = function (search) {
49 49
        url: null
50 50
    };
51 51
52
    // Determines if there is an exclusion in the path.
53
    // @param {Object} element
54
    // @return {Boolean} a value indicating whether the object is excluded
55
    function isExcluded(element) {
56
        var excluded = $(element).is(settings.exclude);
57
        var parent = $(element).parent();
58
        
59
        if (parent && parent.prop("tagName") !== undefined) {
60
            excluded = excluded || parent.is(settings.excluded);
61
            if (!excluded) {
62
                excluded = excluded || isExcluded(parent);
63
            }
64
        }
65
66
        return excluded;
67
    };
68
52 69
    // Walk the tree of a given node.
53 70
    // @param {Object} element
54 71
    // @return {Array} path
@ -58,25 +75,18 @@ String.prototype.endsWith = function (search) {
58 75
        
59 76
        if (tagName != undefined) {
60 77
            var parent = $(element).parent();
61
            if (parent != undefined) {
78
            if (parent && parent.prop("tagName") !=== undefined) {
62 79
                $.each(walkTree($(element).parent()), function (i, node) {
63
                    if ($(node).is(settings.exclude)) {
64
                        tree = null;
65
                    }
66
                    else if (tree !== null) {
67
                        tree.push(node);
68
                    }
80
                    tree.push(node);
69 81
                });
70 82
            }
71 83
            
72
            if (tree !== null) {
73
                if (tagName == "HTML" || tagName == "BODY") {
74
                    tree.push(tagName);
75
                }
76
                else {
77
                    var tagId = $(element).analyticsUniqueId().attr("id");
78
                    tree.push(tagName + '[id="' + tagId + '"]');
79
                }
84
            if (tagName == "HTML" || tagName == "BODY") {
85
                tree.push(tagName);
86
            }
87
            else {
88
                var tagId = $(element).analyticsUniqueId().attr("id");
89
                tree.push(tagName + '[id="' + tagId + '"]');
80 90
            }
81 91
        }
82 92
        
@ -96,12 +106,12 @@ String.prototype.endsWith = function (search) {
96 106
        // Locally scope this variable.
97 107
        $this = $(this);
98 108
99
        if (settings.url && !$this.is(".analytics-captured") && !$this.is(settings.exclude)) {
109
        if (settings.url && !$this.is(".analytics-captured") && !isExcluded($this)) {
100 110
            // Walk the tree.
101 111
            var tree = walkTree($this);
102 112
103 113
            // Make sure the tree does not include an excluded section.
104
            if (tree !== null && tree.length > 0) {
114
            if (tree && tree.length > 0) {
105 115
                // Join all the nodes of the tree.
106 116
                tree = tree.join(' ');
107 117
@ -191,7 +201,7 @@ String.prototype.endsWith = function (search) {
191 201
        var selector = settings.assignTo.join(",");
192 202
193 203
        return this.each(function () {
194
            // Itereate through all elements given on initiation.
204
            // Iterate through all elements given on initiation.
195 205
            $(this).find(selector).andSelf().filter(selector)
196 206
            .each(function () {
197 207
                identifyPath($(this));