segment.js
function Segment(config) {

        this.config = config;

        // Checks condition before calling Segment method
        this.factory = function (method) {
            var _this = this;
            return function () {

                // If a condition has been set, only call the Segment method if it returns true
                if (_this.config.condition && !_this.config.condition(method, arguments)) {
                    _this.debug('Not calling method, condition returned false.', {
                        method: method,
                        arguments: arguments,
                    });
                    return;
                }

                //  No condition set, call the Segment method
                _this.debug('Calling method ' + method + ' with arguments:', arguments);
                return window.analytics[method].apply(analytics, arguments);
            };
        };
    }
function Segment(config) {

        this.config = config;

        // Checks condition before calling Segment method
        this.factory = function (method) {
            var _this = this;
            return function () {

                // If a condition has been set, only call the Segment method if it returns true
                if (_this.config.condition && !_this.config.condition(method, arguments)) {
                    _this.debug('Not calling method, condition returned false.', {
                        method: method,
                        arguments: arguments,
                    });
                    return;
                }

                //  No condition set, call the Segment method
                _this.debug('Calling method ' + method + ' with arguments:', arguments);
                return window.analytics[method].apply(analytics, arguments);
            };
        };
    }
Segment service
@param config
@constructor