PageSourceSearch

https://app.truconversion.com/assets/js/component/truind.js

js truconversion.com collected 2026-10-02 04:07:55 UTC 22,731 bytes, 512 lines download raw bytes

1var xhr;
2var truInd = {
3    base_url: null,
4    account_id: null,
5    account_role: null,
6    uid: null,
7    survey_dirty_bit: false,
8    account_subs: null,
9    is_new_login: 'no',
10    environment: 'production',
11    whitelabel_info: null,
12    domainProtocol: '',
13    appSumo: null,
14    appSumoDealEnd: null,
15    cst: null,
16    setPrimaryVars: function() {
17        if (arguments.length < 4) {
18            throw new Error("TruInd: required arguments length is 4 - given " + arguments.length);
19        }
20        this.base_url = arguments[0];
21        this.account_id = arguments[1];
22        this.account_role = arguments[2];
23        this.is_new_login = arguments[3];
24        if (arguments[4]) {
25            this.environment = arguments[4];//"<?php echo getenv('APPLICATION_ENV');?>"
26        }
27    },
28    setAccountPlan: function() {
29        if (typeof arguments[0] !== 'object' && arguments.length) {
30            throw new Error("TruInd: required argument type is object - given " + typeof arguments[0]);
31        }
32        this.account_subs = arguments[0];
33    },
34    jsonParser: function(e) {
35        var t = typeof e;
36        if (t != "object" || e === null) {
37            if (t == "string")
38                e = '"' + e + '"';
39            return String(e)
40        } else {
41            var n, r, i = [], s = e && e.constructor == Array;
42            for (n in e) {
43                r = e[n];
44                t = typeof r;
45                if (t == "string")
46                    r = '"' + r + '"';
47                else if (t == "object" && r !== null)
48                    r = truInd.jsonParser(r);
49                i.push((s ? "" : '"' + n + '":') + String(r))
50            }
51            return(s ? "[" : "{") + String(i) + (s ? "]" : "}")
52        }
53    },
54    stringify: function(e) {
55        if (typeof JSON === 'undefined' || typeof JSON.stringify !== 'function') {
56            return truInd.jsonParser(e);
57        } else {
58            return JSON.stringify(e);
59        }
60    },
61    parseJSON: function(e) {
62        if (window.JSON && window.JSON.parse) {
63            return window.JSON.parse(e);
64        }
65        if (e === null) {
66            return e;
67        }
68        if (typeof e === "string" && e) {
69            var t = /^[\],:{}\s]*$/, n = /(?:^|:|,)(?:\s*\[)+/g, r = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g, i = /"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g;
70            if (t.test(e.replace(r, "@").replace(i, "]").replace(n, ""))) {
71                return(new Function("return " + e))();
72            }
73        }
74    },
75    validateEmail: function(e) {
76        var filter = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
77        return filter.test(e);
78    },
79    getSelectedDomain: function() {
80        this.getCookie('ti-selected-domain-id');
81    },
82    getSelectedCompany: function() {
83        this.getCookie('ti-selected-account-id');
84    },
85    setSelectedDomain: function(val) {
86        this.setCookie('ti-selected-domain-id', val, 10000);
87    },
88    setSelectedCompany: function(val) {
89        this.setCookie('ti-selected-account-id', val, 10000);
90    },
91    setCookie: function(cname, cvalue, exdays) {
92        var d = new Date();
93        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
94        var expires = "expires=" + d.toUTCString();
95        document.cookie = cname + "=" + cvalue + "; path=/; " + expires;
96    },
97    setSuperCookie: function(name, value, expiry) {
98        var d = new Date();
99        d.setTime(d.getTime() + (expiry));
100        var expires = "expires=" + d.toUTCString();
101        document.cookie = name + "=" + value + "; domain=" + window.location.hostname.replace("app.", "").replace("console.", "") + "; path=/; " + expires;
102    },
103    getSuperCookie: function(name) {
104        var i, x, y, c = document.cookie.split(";");
105        for (i = 0; i < c.length; i++) {
106            x = c[i].substr(0, c[i].indexOf("="));
107            y = c[i].substr(c[i].indexOf("=") + 1);
108            x = x.replace(/^\s+|\s+$/g, "");
109            if (x === name) {
110                return y;
111            }
112        }
113        return null;
114    },
115    getCookie: function(cname) {
116//        console.log(cname);
117        var name = cname + "=";
118        var val = ""
119        var ca = document.cookie.split(';');
120//        console.log(ca);
121        for (var i = 0; i < ca.length; i++) {
122            var c = ca[i];
123            while (c.charAt(0) == ' ')
124                c = c.substring(1);
125            if (c.indexOf(name) == 0)
126                val = c.substring(name.length, c.length);
127        }
128//        console.log(val);
129        return val;
130    },
131    showError: function(selector, text) {
132        $('.form-control[name=' + selector + ']').addClass("parsley-error");
133        $('.form-control[name=' + selector + ']').after('<ul class="parsley-error-list" style="display:block;"><li class="required" style="display: list-item;">' + text + '</li></ul>');
134    },
135    isValidPassword: function(value) {
136        // Here we define all our params
137        var validLength = 8;
138        var minSuccess  = 3,
139        isNumeric   = + /\d+/.test(value),
140        /*isCapitals  = + /[A-Z]+/.test(value),*/
141        isSmall     = + /[a-z]+/.test(value),
142        isSpecial   = + /[!@#$%&\/=\?_\.,:;\-]+/.test(value);
143
144        if (value.length < validLength) { // 8 symbols. We don`t need regexp here
145            return false;
146        }
147
148        if (isNumeric + isSmall + isSpecial < minSuccess) {
149            return false;
150        }
151
152        return true;
153    },
154    validateUrlMain: function(toTest) {
155        var regex = /[a-zA-Z0-9\-,_]+\.[a-zA-Z]{2,3}/;
156        return (regex.test(toTest));
157    },
158    appendParsleyError: function(obj, msg, group) {
159        if (group === undefined) {
160            obj.parent().addClass("parsley-error");
161            obj.after('<ul style="display:block;" class="parsley-error-list"><li style="display: list-item;" class="required">' + msg + '</li></ul>');
162        } else {
163            if (group === "doubleParent") {
164                obj.parent().parent().addClass("parsley-error");
165                obj.parent().parent().append('<ul style="display:block;" class="parsley-error-list"><li style="display: list-item;" class="required">' + msg + '</li></ul>');
166            }else if(group === "inner"){
167                obj.addClass("parsley-error");
168                obj.append('<ul style="display:block;" class="parsley-error-list"><li style="display: list-item;color:#ffffff;padding:0px" class="required">' + msg + '</li></ul>');
169            }
170        }
171    },
172    appendParsleyErrorBorder: function(obj) {
173        obj.parent().addClass("error-border");
174    },
175    removeParsleyErrors: function(selector) {
176        if(selector !== undefined){
177            $(selector).find(".parsley-error").removeClass("parsley-error");
178            $(selector).find(".parsley-error-list, .parsley-errors-list").remove();
179        }else{
180            $("form").find(".parsley-error").removeClass("parsley-error");
181            $(".parsley-error-list").remove();
182            $("form").find(".error-border").removeClass("error-border");
183        }
184    },
185    handleMatchURLPlaceHolder: function(urlTypeRef, selectedDomain) {
186        var screenShot = false;
187        switch (urlTypeRef.val()) {
188            case "simple":
189                $("#page-url").attr("placeholder", "e.g. " + selectedDomain) + "/";
190                $("#url-help-text").html("Simple match allows you to target pages without query parameters and fragments.");
191                break;
192            case "exact":
193                $("#page-url").attr("placeholder", "e.g. " + selectedDomain + "/?product=X");
194                $("#url-help-text").html("Exact match allows you to target pages with query parameters and fragments.");
195                break;
196            case "starts":
197                $("#page-url").attr("placeholder", "e.g. " + selectedDomain + "/page/");
198                $("#url-help-text").html("Starts with allows you to target pages for which a URL starts in a certain way.");
199                screenShot = true;
200                break;
201            case "ends":
202                $("#page-url").attr("placeholder", "e.g. /detail");
203                $("#url-help-text").html("Ends with allows you to target pages for which a URL ends in a certain way.");
204                screenShot = true;
205                break;
206            case "contains":
207                $("#page-url").attr("placeholder", "e.g. register/");
208                $("#url-help-text").html("Contains allows you to target pages that contain something specific in their URL.");
209                screenShot = true;
210                break;
211            case "regexp":
212                $("#page-url").attr("placeholder", "e.g. /pages/[^/]+");
213                $("#url-help-text").html("Javascript Regular Expression allows you to target pages with search patterns.");
214                screenShot = true;
215                break;
216        }
217
218        if (arguments[2] !== undefined) {
219            if (arguments[2] === "heatmap") {
220                if (screenShot) {
221                    arguments[3].show();
222                } else {
223                    arguments[3].hide();
224                }
225            }
226        }
227
228        $("#page-url-container").removeClass("parsley-error");
229        $("#page-url-container").parent().find("ul").remove();
230    },
231    validateMatchUrl: function(url, urlType) {
232        var isError = false;
233        var selectedDomain = $.trim($("#domain_selected_tour > a:first-child small + span").text());
234        switch (urlType) {
235            case "simple":
236            case "starts":
237                var pattern = '^((http|https)://)?(www\.)?' + selectedDomain;
238                var r = RegExp(pattern, 'i');
239                if (!(r.test(url) && (url.indexOf('?') === -1) && (url.indexOf('#') === -1))) {
240                    isError = true;
241                }
242                break;
243            case "exact":
244                var pattern = '^((http|https)://)?(www\.)?' + selectedDomain;
245                var r = RegExp(pattern, 'i');
246                if (!r.test(url)) {
247                    isError = true;
248                }
249                break;
250            case "ends":
251                var pattern = '^' + selectedDomain;
252                var p1 = "(http|https)://"; //to check if http|https includes
253                var p2 = "(www\.)?" + selectedDomain; //to check if selected domain exist with or without www
254                var r = RegExp(pattern, 'i');
255                var r1 = RegExp(p1, 'i');
256                var r2 = RegExp(p2, 'i');
257                if (r1.test(url) || r2.test(url) || !url.trim()) {
258                    isError = true;
259                }
260                break;
261            case "contains":
262                var pattern = '^' + selectedDomain;
263                var p1 = "(http|https)://"; //to check if http|https includes
264                var p2 = "(www)?" + selectedDomain; //to check if selected domain exist with or without www
265                var r = RegExp(pattern, 'i');
266                var r1 = RegExp(p1, 'i');
267                var r2 = RegExp(p2, 'i');
268                if (r1.test(url) || r2.test(url) || !url.trim()) {
269                    isError = true;
270                }
271                break;
272            case "regexp":
273                break;
274        }
275
276        return isError;
277    },
278    validateURL: function() {
279        var args = arguments[0];
280        var isError = false;
281        var selectedDomain = $.trim($("#domain_selected_tour > a:first-child small + span").text());
282        var pattern = '^((http|https)://)?(www\.)?' + selectedDomain;
283        var r = RegExp(pattern, 'i');
284
285        if (!(r.test(args.url) && (args.url.indexOf('?') === -1) && (args.url.indexOf('#') === -1))) {
286            isError = true;
287        }
288        return isError;
289    },
290    compareTime: function(sd, st, ed, et) {
291        var stt = new Date(sd + 'T' + st);
292        var endt = new Date(ed + 'T' + et);
293        stt = stt.getTime();
294        endt = endt.getTime();
295        if (stt > endt) {
296            return false;
297        }
298        return true;
299    },
300    getTimeZone: function() {
301        var offset = new Date().getTimezoneOffset(), o = Math.abs(offset);
302        return (offset < 0 ? "+" : "-") + ("00" + Math.floor(o / 60)).slice(-2) + ":" + ("00" + (o % 60)).slice(-2);
303    },
304    uriParser: function(uri) {
305        var a = document.createElement('a');
306        a.href = uri;
307
308        return {
309            host: a.host,
310            hostname: a.hostname,
311            port: a.port,
312            pathname: a.pathname,
313            search: a.search,
314            hash: a.hash
315        };
316    },
317    crossDomainValidation: function(pageUrl, selector) {
318        var dfd = $.Deferred();
319        if (truInd.validateUrlMain(pageUrl)) {
320            if (xhr && xhr.readyState != 4) {
321                xhr.abort();
322            }
323            xhr = $.post('/v2/api/', {command: "cross.sub.domain.validate", pageUrl: pageUrl}, function(response) {
324                if (response.Status == 'Error') {
325                    $(selector).parent().addClass("parsley-error");
326                    $(selector).after('<ul class="parsley-errors-list" style="display:block;"><li class="required" style="display: list-item;">' + response.Message + '</li></ul>');
327                    dfd.resolve(false);
328                } else {
329                    dfd.resolve(true);
330                }
331
332            });
333        } else {
334            $(selector).parent().addClass("parsley-error");
335            $(selector).after('<ul class="parsley-errors-list" style="display:block;"><li class="required" style="display: list-item;">Please provide valid URL</li></ul>');
336            return false;
337        }
338        return dfd.promise();
339    },
340    compareTime: function(sd, st, ed, et) {
341        var stt = new Date(sd + 'T' + st);
342        var endt = new Date(ed + 'T' + et);
343        stt = stt.getTime();
344        endt = endt.getTime();
345        console.log("Time1: " + stt + " Time2: " + endt);
346
347        if (stt > endt) {
348            return false;
349        }
350        return true;
351    },
352            scrapeUrlForEvents: function(pageUrl) {
353                var dfd = $.Deferred();
354                $.ajax({
355                    url: "/v2/api/",
356                    type: "POST",
357                    data: {command: "scrape.url.for.events", pageUrl: pageUrl},
358                    success: function(response) {
359                        if (response.Data) {
360                            dfd.resolve(response.Data);
361                        } else {
362                            dfd.resolve(false);
363                        }
364                    }
365                });
366                return dfd.promise();
367            },
368    commaSeparateNumber: function(val) {
369        while (/(\d+)(\d{3})/.test(val.toString())) {
370            val = val.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
371        }
372        return val;
373    },
374    number_format: function(number, decimals, decPoint, thousandsSep) {
375        number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
376        var n = !isFinite(+number) ? 0 : +number;
377        var prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
378        var sep = (typeof thousandsSep === 'undefined') ? ',' : thousandsSep;
379        var dec = (typeof decPoint === 'undefined') ? '.' : decPoint;
380        var s = '';
381
382        var toFixedFix = function(n, prec) {
383            var k = Math.pow(10, prec);
384            return '' + (Math.round(n * k) / k)
385                    .toFixed(prec);
386        };
387
388        // @todo: for IE parseFloat(0.55).toFixed(0) = 0;
389        s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
390        if (s[0].length > 3) {
391            s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
392        }
393        if ((s[1] || '').length < prec) {
394            s[1] = s[1] || '';
395            s[1] += new Array(prec - s[1].length + 1).join('0');
396        }
397
398        return s.join(dec);
399    },
400    saveInStorage: function(key, value) {
401        if (typeof (Storage) !== "undefined") {
402            window["localStorage"].setItem(key, value);
403        }
404    },
405    getFromStorage: function(key) {
406        if (typeof (Storage) !== "undefined") {
407            return window["localStorage"].getItem(key);
408        }
409    },
410    baStatParser: function() {
411        //$(".ba-filter-loader").hide();
412        if(this.getFromStorage("tc_ba_stats_" + truInd.getCookie('ti-selected-domain-id')) !== null){
413            var stats = this.parseJSON(this.getFromStorage("tc_ba_stats_" + truInd.getCookie('ti-selected-domain-id')));
414            if (Object.keys(stats).length) {
415                if ($(".ba-filter").length) {
416                    var start = $("#reportrange span").attr("data-attr-start"), end = $("#reportrange span").attr("data-attr-end"), key = start + end;
417                    if (stats[key] !== undefined) {
418                        var pageViews = ((stats[key].pageviews != '0') ? parseInt(stats[key].pageviews.replace(/,/g, '')) : 0), pageSessions = ((stats[key].sessions != '0') ? parseInt(stats[key].sessions.replace(/,/g, '')) : 0);
419                        var activeRate = (pageViews && pageSessions) ? (pageViews / pageSessions).toPrecision(4) : 0;
420                        $(".ba-sessions .numbers .active").text(stats[key].sessions);
421                        $(".ba-users .numbers .active").text(stats[key].users);
422                        $(".ba-pageviews .numbers .active").text(stats[key].pageviews);
423                        $(".ba-session-pageviews .numbers .active").text(activeRate);
424                        $(".ba-filter-loader").hide();
425                    }
426                }
427            }
428        }else{
429            $.ajax({
430                url: truInd.base_url + '/v2/api/',
431                type: "GET",
432                data: {command: "fetch_ba_stats", domain_id: truInd.getCookie('ti-selected-domain-id'), is_custom: 0, today: moment().tz(truInd.timeZone).format("YYYY-MM-DD"), yesterday: moment().tz(truInd.timeZone).subtract(1, 'days').format("YYYY-MM-DD"), last_7_days: moment().tz(truInd.timeZone).subtract(6, 'days').format("YYYY-MM-DD"), this_month_start: moment().tz(truInd.timeZone).startOf('month').format("YYYY-MM-DD"), this_month_end: moment().tz(truInd.timeZone).endOf('month').format("YYYY-MM-DD"), last_month_start: moment().tz(truInd.timeZone).subtract(1, 'month').startOf('month').format("YYYY-MM-DD"), last_month_end: moment().tz(truInd.timeZone).subtract(1, 'month').endOf('month').format("YYYY-MM-DD") },
433                success: function(response){
434                    if(response.status === 200){
435                        var data = response.data;
436                        truInd.saveInStorage("tc_ba_stats_" + truInd.getCookie('ti-selected-domain-id'), truInd.stringify(data));
437                        truInd.setSuperCookie("tc_ba_stat_update_" + truInd.getCookie('ti-selected-domain-id'), 1, (6 * 60 * 1000));
438                        var stats = truInd.parseJSON(truInd.getFromStorage("tc_ba_stats_" + truInd.getCookie('ti-selected-domain-id')));
439                        if (Object.keys(stats).length) {
440                            if ($(".ba-filter").length) {
441                                var start = $("#reportrange span").attr("data-attr-start"), end = $("#reportrange span").attr("data-attr-end"), key = start + end;
442                                if (stats[key] !== undefined) {
443                                    var pageViews = ((stats[key].pageviews != '0') ? parseInt(stats[key].pageviews.replace(/,/g, '')) : 0), pageSessions = ((stats[key].sessions != '0') ? parseInt(stats[key].sessions.replace(/,/g, '')) : 0);
444                                    var activeRate = (pageViews && pageSessions) ? (pageViews / pageSessions).toPrecision(4) : 0;
445                                    $(".ba-sessions .numbers .active").text(stats[key].sessions);
446                                    $(".ba-users .numbers .active").text(stats[key].users);
447                                    $(".ba-pageviews .numbers .active").text(stats[key].pageviews);
448                                    $(".ba-session-pageviews .numbers .active").text(activeRate);
449                                    $(".ba-filter-loader").hide();
450                                }
451                            }
452                        }
453                    }
454                }
455            });
456        }
457    },
458    addParameterToURL: function(url, param){
459        var _url = url;
460        _url += (_url.split('?')[1] ? '&':'?') + param;
461        return _url;
462    },
463    isset: function () {
464        var a = arguments;
465        var l = a.length;
466        var i = 0;
467        var undef;
468        if (l === 0) {
469            throw new Error('Empty isset');
470        }
471        while (i !== l) {
472            if (a[i] === undef || a[i] === null) {
473                return false;
474            }
475            i++;
476        }
477        return true;
478    },
479    escapeHtml: function(text) {
480        var map = {
481            '&': '&amp;',
482            '<': '&lt;',
483            '>': '&gt;',
484            '"': '&quot;',
485            "'": '&#039;'
486        };
487        return text.replace(/[&<>"']/g, function(m) { return map[m]; });
488    },
489};
490
491var csrf_token_name = $('meta[name="csrf-param"]').attr('content');
492var csrf_token = $('meta[name="csrf-token"]').attr('content');
493$(document).on('submit', 'form', function(e) {
494    // e.preventDefault();
495    var form = $(e.target);
496    if (form.attr('method').toUpperCase() === 'POST') {
497        form.not(':has(input#' + csrf_token_name + ')').append(
498            '<input type="hidden" id="token_name" name="token_name" value="' + csrf_token_name + '" /><input type="hidden" id="' + csrf_token_name + '" name="' + csrf_token_name + '" value="' + csrf_token + '" />'
499        );
500    }
501});
502
503$.ajaxPrefilter(function(options) {
504    if (options.type.toUpperCase() === 'POST') {
505        if ($.type(options.data) === 'object') {
506            options.data['token_name'] = csrf_token_name;
507            options.data[csrf_token_name] = csrf_token;
508        } else if ($.type(options.data) === 'string') {
509            options.data = options.data + '&token_name=' + csrf_token_name + '&' + csrf_token_name + '=' + csrf_token;
510        }
511    }
512});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.