Browse Source

Fixed issue with exclusions

bmallred 11 years ago
parent
commit
2f4caad54f
1 changed files with 28 additions and 18 deletions
  1. 28 18
      jquery-analytics.js

+ 28 - 18
jquery-analytics.js

49
        url: null
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
    // Walk the tree of a given node.
69
    // Walk the tree of a given node.
53
    // @param {Object} element
70
    // @param {Object} element
54
    // @return {Array} path
71
    // @return {Array} path
58
        
75
        
59
        if (tagName != undefined) {
76
        if (tagName != undefined) {
60
            var parent = $(element).parent();
77
            var parent = $(element).parent();
61
            if (parent != undefined) {
78
            if (parent && parent.prop("tagName") !=== undefined) {
62
                $.each(walkTree($(element).parent()), function (i, node) {
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
        // Locally scope this variable.
106
        // Locally scope this variable.
97
        $this = $(this);
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
            // Walk the tree.
110
            // Walk the tree.
101
            var tree = walkTree($this);
111
            var tree = walkTree($this);
102
112
103
            // Make sure the tree does not include an excluded section.
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
                // Join all the nodes of the tree.
115
                // Join all the nodes of the tree.
106
                tree = tree.join(' ');
116
                tree = tree.join(' ');
107
117
191
        var selector = settings.assignTo.join(",");
201
        var selector = settings.assignTo.join(",");
192
202
193
        return this.each(function () {
203
        return this.each(function () {
194
            // Itereate through all elements given on initiation.
204
            // Iterate through all elements given on initiation.
195
            $(this).find(selector).andSelf().filter(selector)
205
            $(this).find(selector).andSelf().filter(selector)
196
            .each(function () {
206
            .each(function () {
197
                identifyPath($(this));
207
                identifyPath($(this));