/
frontend.js
643 lines (569 loc) · 22.8 KB
/
frontend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
/**
* Developer's Notice:
*
* Note: JS in this file (and this file itself) is not garunteed backwards compatibility. JS can be added, changed or removed at any time without notice.
* For more information see the `Backwards Compatibility Guidelines for Developers` section of the README.md file.
*/
/**
* Handles:
* - JS Events handling
*
* @since 6.0.12
*/
var MonsterInsights = function(){
/* MonsterInsights JS events tracking works on all major browsers, including IE starting at IE 7, via polyfills for any major JS function used that
is not supported by at least 95% of the global and/or US browser marketshare. Currently, IE 7 & 8 which as of 2/14/17 have under 0.25% global marketshare, require
us to polyfill Array.prototype.lastIndexOf, and if they continue to drop, we might remove this polyfill at some point. In that case note that events tracking
for IE 7/8 will continue to work, with the exception of events tracking of downloads. */
var lastClicked = [];
var internalAsOutboundCategory = '';
this.setLastClicked = function(valuesArray,fieldsArray,tracked){
valuesArray = typeof valuesArray !== 'undefined' ? valuesArray : [];
fieldsArray = typeof fieldsArray !== 'undefined' ? fieldsArray : [];
tracked = typeof tracked !== 'undefined' ? tracked : false;
lastClicked.valuesArray = valuesArray;
lastClicked.fieldsArray = fieldsArray;
};
this.getLastClicked = function () {
return lastClicked;
};
this.setInternalAsOutboundCategory = function( category ){
internalAsOutboundCategory = category;
};
this.getInternalAsOutboundCategory = function () {
return internalAsOutboundCategory;
};
this.sendEvent = function ( fieldsArray ) {
__gaTrackerSend( [], fieldsArray );
};
function __gaTrackerIsDebug () {
if ( window.monsterinsights_debug_mode ) {
return true;
} else {
return false;
}
}
function __gaTrackerSend ( valuesArray, fieldsArray ) {
valuesArray = typeof valuesArray !== 'undefined' ? valuesArray : [];
fieldsArray = typeof fieldsArray !== 'undefined' ? fieldsArray : {};
__gaTracker( 'send', fieldsArray );
lastClicked.valuesArray = valuesArray;
lastClicked.fieldsArray = fieldsArray;
lastClicked.tracked = true;
__gaTrackerLog( 'Tracked: ' + valuesArray.type );
__gaTrackerLog( lastClicked );
}
function __gaTrackerNotSend ( valuesArray ) {
valuesArray = typeof valuesArray !== 'undefined' ? valuesArray : [];
lastClicked.valuesArray = valuesArray;
lastClicked.fieldsArray = [];
lastClicked.tracked = false;
__gaTrackerLog( 'Not Tracked: ' + valuesArray.exit );
__gaTrackerLog( lastClicked );
}
function __gaTrackerLog ( message ) {
if ( __gaTrackerIsDebug() ) {
console.dir( message );
}
}
function __gaTrackerStringTrim( x ) {
return x.replace(/^\s+|\s+$/gm,'');
}
function __gaTrackerGetDomain() {
var i=0,currentdomain=document.domain,p=currentdomain.split('.'),s='_gd'+(new Date()).getTime();
while(i<(p.length-1) && document.cookie.indexOf(s+'='+s)==-1){
currentdomain = p.slice(-1-(++i)).join('.');
document.cookie = s+"="+s+";domain="+currentdomain+";";
}
document.cookie = s+"=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain="+currentdomain+";";
return currentdomain;
}
function __gaTrackerGetExtension( extension ) {
extension = extension.toString();
extension = extension.substring( 0, (extension.indexOf( "#" ) == -1 ) ? extension.length : extension.indexOf( "#" ) ); /* Remove the anchor at the end, if there is one */
extension = extension.substring( 0, (extension.indexOf( "?" ) == -1 ) ? extension.length : extension.indexOf( "?" ) ); /* Remove the query after the file name, if there is one */
extension = extension.substring( extension.lastIndexOf( "/" ) + 1, extension.length ); /* Remove everything before the last slash in the path */
if ( extension.length > 0 && extension.indexOf('.') !== -1 ) { /* If there's a period left in the URL, then there's a extension. Else it is not a extension. */
extension = extension.substring( extension.indexOf( "." ) + 1 ); /* Remove everything but what's after the first period */
return extension;
} else {
return "";
}
}
function __gaTrackerLoaded() {
return typeof(__gaTracker) !== 'undefined' && __gaTracker && __gaTracker.hasOwnProperty( "loaded" ) && __gaTracker.loaded == true; /* jshint ignore:line */
}
function __gaTrackerTrackedClick( event ) {
return event.which == 1 || event.which == 2 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;
}
function __gaTrackerGetDownloadExtensions() {
var download_extensions = [];
if ( typeof monsterinsights_frontend.download_extensions == 'string' ) {
download_extensions = monsterinsights_frontend.download_extensions.split(",");
}
return download_extensions;
}
function __gaTrackerGetInboundPaths() {
var inbound_paths = [];
if ( typeof monsterinsights_frontend.inbound_paths == 'string' ) {
inbound_paths = JSON.parse( monsterinsights_frontend.inbound_paths );
}
return inbound_paths;
}
function __gaTrackerTrackedClickType( event ) {
if ( event.which == 1 ) {
return 'event.which=1';
} else if ( event.which == 2 ) {
return 'event.which=2';
} else if ( event.metaKey ){
return 'metaKey';
} else if ( event.ctrlKey ) {
return 'ctrlKey';
} else if ( event.shiftKey ) {
return 'shiftKey';
} else if ( event.altKey ) {
return 'altKey';
} else {
return '';
}
}
function __gaTrackerLinkType( el ) {
var download_extensions = __gaTrackerGetDownloadExtensions();
var inbound_paths = __gaTrackerGetInboundPaths();
var type = 'unknown';
var link = el.href;
var extension = __gaTrackerGetExtension( el.href );
var currentdomain = __gaTrackerGetDomain();
var hostname = el.hostname;
var protocol = el.protocol;
var pathname = el.pathname;
link = link.toString();
var index, len;
var category = el.getAttribute("data-vars-ga-category");
if ( category ) {
return category;
}
if ( link.match( /^javascript\:/i ) ) {
type = 'internal'; /* if it's a JS link, it's internal */
} else if ( protocol && protocol.length > 0 && ( __gaTrackerStringTrim( protocol ) == 'tel' || __gaTrackerStringTrim( protocol ) == 'tel:' ) ) { /* If it's a telephone link */
type = "tel";
} else if ( protocol && protocol.length > 0 && ( __gaTrackerStringTrim( protocol ) == 'mailto' || __gaTrackerStringTrim( protocol ) == 'mailto:' ) ) { /* If it's a email */
type = "mailto";
} else if ( hostname && currentdomain && hostname.length > 0 && currentdomain.length > 0 && ! hostname.endsWith( '.' + currentdomain) && hostname !== currentdomain ) { /* If it's a outbound */
type = "external";
} else if ( pathname && JSON.stringify( inbound_paths ) != "{}" && pathname.length > 0 ) { /* If it's an internal as outbound */
var inbound_paths_length = inbound_paths.length;
for ( var inbound_paths_index = 0; inbound_paths_index < inbound_paths_length; inbound_paths_index ++ ) {
if ( inbound_paths[ inbound_paths_index ].path && inbound_paths[ inbound_paths_index ].label && inbound_paths[ inbound_paths_index ].path.length > 0 && inbound_paths[ inbound_paths_index ].label.length > 0 && pathname.startsWith( inbound_paths[ inbound_paths_index ].path ) ) {
type = "internal-as-outbound";
internalAsOutboundCategory = "outbound-link-" + inbound_paths[ inbound_paths_index ].label;
break;
}
}
/* Enable window.monsterinsights_experimental_mode at your own risk. We might eventually remove it. Also you may/can/will burn through GA quota for your property quickly. */
} else if ( hostname && window.monsterinsights_experimental_mode && hostname.length > 0 && document.domain.length > 0 && hostname !== document.domain ) { /* If it's a cross-hostname link */
type = "cross-hostname";
}
if ( extension && ( type === 'unknown' || 'external' === type ) && download_extensions.length > 0 && extension.length > 0 ) { /* If it's a download */
for ( index = 0, len = download_extensions.length; index < len; ++index ) {
if ( download_extensions[ index ].length > 0 && ( link.endsWith( download_extensions[ index ] ) || download_extensions[ index ] == extension ) ) {
type = "download";
break;
}
}
}
if ( type === 'unknown' ) {
type = 'internal';
}
return type;
}
function __gaTrackerLinkTarget( el, event ) {
/* Is actual target set and not _(self|parent|top)? */
var target = ( el.target && !el.target.match( /^_(self|parent|top)$/i ) ) ? el.target : false;
/* Assume a target if Ctrl|shift|meta-click */
if ( event.ctrlKey || event.shiftKey || event.metaKey || event.which == 2 ) {
target = "_blank";
}
return target;
}
function __gaTrackerGetTitle( el ) {
if ( el.getAttribute("data-vars-ga-label") && el.getAttribute("data-vars-ga-label").replace(/\n/ig, '') ) {
return el.getAttribute("data-vars-ga-label").replace(/\n/ig, '');
} else if ( el.title && el.title.replace(/\n/ig, '') ) {
return el.title.replace(/\n/ig, '');
} else if ( el.innerText && el.innerText.replace(/\n/ig, '') ) {
return el.innerText.replace(/\n/ig, '');
} else if ( el.getAttribute('aria-label') && el.getAttribute('aria-label').replace(/\n/ig, '') ) {
return el.getAttribute('aria-label').replace(/\n/ig, '');
} else if ( el.alt && el.alt.replace(/\n/ig, '') ) {
return el.alt.replace(/\n/ig, '');
} else if ( el.textContent && el.textContent.replace(/\n/ig, '') ) {
return el.textContent.replace(/\n/ig, '');
} else {
return undefined;
}
}
function __gaTrackerGetInnerTitle( el ) {
var children = el.children;
var count = 0;
var child;
var value;
for (var i = 0; i < children.length; i++) {
child = children[i];
value = __gaTrackerGetTitle( child );
if ( value ) {
return value;
}
/* max search 100 elements to ensure performance */
if ( count == 99 ) {
return undefined;
}
count++;
}
return undefined;
}
function __gaTrackerClickEvent( event ) {
var el = event.srcElement || event.target;
var valuesArray = [];
var fieldsArray;
/* Start Values Array */
valuesArray.el = el;
valuesArray.ga_loaded = __gaTrackerLoaded();
valuesArray.click_type = __gaTrackerTrackedClickType( event );
/* If GA is blocked or not loaded, or not main|middle|touch click then don't track */
if ( ! __gaTrackerLoaded() || ! __gaTrackerTrackedClick( event ) ) {
valuesArray.exit = 'loaded';
__gaTrackerNotSend( valuesArray );
return;
}
/* Loop up the DOM tree through parent elements if clicked element is not a link (eg: an image inside a link) */
while ( el && (typeof el.tagName == 'undefined' || el.tagName.toLowerCase() != 'a' || ! el.href ) ) {
el = el.parentNode;
}
/* if a link with valid href has been clicked */
if ( el && el.href && ! el.hasAttribute('xlink:href') ) {
var link = el.href; /* What link are we tracking */
var extension = __gaTrackerGetExtension( el.href ); /* What extension is this link */
var download_extensions = __gaTrackerGetDownloadExtensions(); /* Let's get the extensions to track */
var inbound_paths = __gaTrackerGetInboundPaths(); /* Let's get the internal paths to track */
var home_url = monsterinsights_frontend.home_url; /* Let's get the url to compare for external/internal use */
var currentdomain = __gaTrackerGetDomain(); /* What domain are we on? */
var type = __gaTrackerLinkType( el ); /* What type of link is this? */
var target = __gaTrackerLinkTarget( el, event ); /* Is a new tab/window being opened? */
var action = el.getAttribute("data-vars-ga-action");
var label = el.getAttribute("data-vars-ga-label");
/* Element */
valuesArray.el = el; /* el is an a element so we can parse it */
valuesArray.el_href = el.href; /* "http://example.com:3000/pathname/?search=test#hash" */
valuesArray.el_protocol = el.protocol; /* "http:" */
valuesArray.el_hostname = el.hostname; /* "example.com" */
valuesArray.el_port = el.port; /* "3000" */
valuesArray.el_pathname = el.pathname; /* "/pathname/" */
valuesArray.el_search = el.search; /* "?search=test" */
valuesArray.el_hash = el.hash; /* "#hash" */
valuesArray.el_host = el.host; /* "example.com:3000" */
/* Settings */
valuesArray.debug_mode = __gaTrackerIsDebug(); /* "example.com:3000" */
valuesArray.download_extensions = download_extensions; /* Let's get the extensions to track */
valuesArray.inbound_paths = inbound_paths; /* Let's get the internal paths to track */
valuesArray.home_url = home_url; /* Let's get the url to compare for external/internal use */
/* Parsed/Logic */
valuesArray.link = link; /* What link are we tracking */
valuesArray.extension = extension; /* What extension is this link */
valuesArray.type = type; /* What type of link is this */
valuesArray.target = target; /* Is a new tab/window being opened? */
valuesArray.title = __gaTrackerGetTitle( el ); /* Try link title, then text content */
/* only find innerTitle if we need one */
if ( ! valuesArray.label && ! valuesArray.title ) {
valuesArray.title = __gaTrackerGetInnerTitle( el );
}
/* Let's track everything but internals (that aren't internal-as-externals) and javascript */
if ( type !== 'internal' && type !== 'javascript' ) {
var __gaTrackerHitBackRun = false; /* Tracker has not yet run */
/* HitCallback to open link in same window after tracker */
var __gaTrackerHitBack = function() {
/* Run the hitback only once */
if ( __gaTrackerHitBackRun ){
return;
}
__gaTrackerHitBackRun = true;
window.location.href = link;
};
var __gaTrackerNoRedirectExternal = function() {
valuesArray.exit = 'external';
__gaTrackerNotSend( valuesArray );
};
var __gaTrackerNoRedirectInboundAsExternal = function() {
valuesArray.exit = 'internal-as-outbound';
__gaTrackerNotSend( valuesArray );
};
var __gaTrackerNoRedirectCrossHostname = function() {
valuesArray.exit = 'cross-hostname';
__gaTrackerNotSend( valuesArray );
};
if ( target || type == 'mailto' || type == 'tel' ) { /* If target opens a new window then just track */
if ( type == 'download' ) {
fieldsArray = {
hitType : 'event',
eventCategory : 'download',
eventAction : action || link,
eventLabel : label || valuesArray.title,
};
__gaTrackerSend( valuesArray, fieldsArray );
} else if ( type == 'tel' ) {
fieldsArray = {
hitType : 'event',
eventCategory : 'tel',
eventAction : action || link,
eventLabel : label || valuesArray.title.replace('tel:', ''),
};
__gaTrackerSend( valuesArray, fieldsArray );
} else if ( type == 'mailto' ) {
fieldsArray = {
hitType : 'event',
eventCategory : 'mailto',
eventAction : action || link,
eventLabel : label || valuesArray.title.replace('mailto:', ''),
};
__gaTrackerSend( valuesArray, fieldsArray );
} else if ( type == 'internal-as-outbound' ) {
fieldsArray = {
hitType : 'event',
eventCategory : internalAsOutboundCategory,
eventAction : action || link,
eventLabel : label || valuesArray.title,
};
__gaTrackerSend( valuesArray, fieldsArray );
} else if ( type == 'external' ) {
fieldsArray = {
hitType: 'event',
eventCategory:'outbound-link',
eventAction: action || link,
eventLabel: label || valuesArray.title,
};
__gaTrackerSend( valuesArray, fieldsArray );
} else if ( type == 'cross-hostname' ) {
fieldsArray = {
hitType: 'event',
eventCategory:'cross-hostname',
eventAction: action || link,
eventLabel: label || valuesArray.title,
};
__gaTrackerSend( valuesArray, fieldsArray );
} else {
if ( type && type != 'internal' ) {
fieldsArray = {
hitType: 'event',
eventCategory: type,
eventAction: action || link,
eventLabel: label || valuesArray.title,
};
__gaTrackerSend( valuesArray, fieldsArray );
} else {
valuesArray.exit = 'type';
__gaTrackerNotSend( valuesArray );
}
}
} else {
/* Prevent standard click, track then open */
if ( type != 'cross-hostname' && type != 'external' && type != 'internal-as-outbound' ) {
if (! event.defaultPrevented ) {
if ( event.preventDefault ) {
event.preventDefault();
} else {
event.returnValue = false;
}
}
}
if ( type == 'download' ) {
fieldsArray = {
hitType : 'event',
eventCategory : 'download',
eventAction : action || link,
eventLabel : label || valuesArray.title,
hitCallback : __gaTrackerHitBack,
};
__gaTrackerSend( valuesArray, fieldsArray );
} else if ( type == 'internal-as-outbound' ) {
window.onbeforeunload = function(e) {
if (! event.defaultPrevented ) {
if ( event.preventDefault ) {
event.preventDefault();
} else {
event.returnValue = false;
}
}
fieldsArray = {
hitType : 'event',
eventCategory : internalAsOutboundCategory,
eventAction : action || link,
eventLabel : label || valuesArray.title,
hitCallback : __gaTrackerHitBack,
};
if ( navigator.sendBeacon ) {
fieldsArray.transport = 'beacon';
}
__gaTrackerSend( valuesArray, fieldsArray );
setTimeout( __gaTrackerHitBack, 1000 );
};
} else if ( type == 'external' ) {
window.onbeforeunload = function(e) {
if (! event.defaultPrevented ) {
if ( event.preventDefault ) {
event.preventDefault();
} else {
event.returnValue = false;
}
}
fieldsArray = {
hitType : 'event',
eventCategory : 'outbound-link',
eventAction : action || link,
eventLabel : label || valuesArray.title,
hitCallback : __gaTrackerHitBack,
};
if ( navigator.sendBeacon ) {
fieldsArray.transport = 'beacon';
}
__gaTrackerSend( valuesArray, fieldsArray );
setTimeout( __gaTrackerHitBack, 1000 );
};
} else if ( type == 'cross-hostname' ) {
window.onbeforeunload = function(e) {
if (! event.defaultPrevented ) {
if ( event.preventDefault ) {
event.preventDefault();
} else {
event.returnValue = false;
}
}
fieldsArray = {
hitType : 'event',
eventCategory : 'cross-hostname',
eventAction : action || link,
eventLabel : label || valuesArray.title,
hitCallback : __gaTrackerHitBack,
};
if ( navigator.sendBeacon ) {
fieldsArray.transport = 'beacon';
}
__gaTrackerSend( valuesArray, fieldsArray );
setTimeout( __gaTrackerHitBack, 1000 );
};
} else {
if ( type && type !== 'internal' ) {
fieldsArray = {
hitType: 'event',
eventCategory: type,
eventAction: action || link,
eventLabel: label || valuesArray.title,
hitCallback : __gaTrackerHitBack,
};
__gaTrackerSend( valuesArray, fieldsArray );
} else {
valuesArray.exit = 'type';
__gaTrackerNotSend( valuesArray );
}
}
if ( type != 'external' && type != 'cross-hostname' && type != 'internal-as-outbound' ) {
/* Run hitCallback again if GA takes longer than 1 second */
setTimeout( __gaTrackerHitBack, 1000 );
} else {
if ( type == 'external' ) {
setTimeout( __gaTrackerNoRedirectExternal, 1100 );
} else if ( type == 'cross-hostname' ) {
setTimeout( __gaTrackerNoRedirectCrossHostname, 1100 );
} else {
setTimeout( __gaTrackerNoRedirectInboundAsExternal, 1100 );
}
}
}
} else {
valuesArray.exit = 'internal';
__gaTrackerNotSend( valuesArray );
}
} else {
valuesArray.exit = 'notlink';
__gaTrackerNotSend( valuesArray );
}
}
var prevHash = window.location.hash;
function __gaTrackerHashChangeEvent() {
/* Todo: Ready this section for JS unit testing */
if ( monsterinsights_frontend.hash_tracking === "true" && prevHash != window.location.hash ) {
prevHash = window.location.hash;
__gaTracker('set', 'page', location.pathname + location.search + location.hash );
__gaTracker('send', 'pageview' );
__gaTrackerLog( "Hash change to: " + location.pathname + location.search + location.hash );
} else {
__gaTrackerLog( "Hash change to (untracked): " + location.pathname + location.search + location.hash );
}
}
/* Attach the event to all clicks in the document after page has loaded */
var __gaTrackerWindow = window;
if ( __gaTrackerWindow.addEventListener ) {
__gaTrackerWindow.addEventListener(
"load",
function() {
document.body.addEventListener(
"click",
__gaTrackerClickEvent,
false
);
},
false
);
window.addEventListener("hashchange", __gaTrackerHashChangeEvent, false );
} else {
if ( __gaTrackerWindow.attachEvent ) {
__gaTrackerWindow.attachEvent(
"onload",
function() {
document.body.attachEvent( "onclick", __gaTrackerClickEvent);
}
);
window.attachEvent( "onhashchange", __gaTrackerHashChangeEvent);
}
}
if (typeof String.prototype.endsWith !== 'function') {
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
}
if (typeof String.prototype.startsWith !== 'function') {
String.prototype.startsWith = function(prefix) {
return this.indexOf(prefix) === 0;
};
}
if ( typeof Array.prototype.lastIndexOf !== 'function' ) {
Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) {
'use strict';
if (this === void 0 || this === null) {
throw new TypeError();
}
var n, k,
t = Object(this),
len = t.length >>> 0; /* jshint ignore:line */
if (len === 0) {
return -1;
}
n = len - 1;
if (arguments.length > 1) {
n = Number(arguments[1]);
if (n != n) {
n = 0;
}
else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { /* jshint ignore:line */
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
for (k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); k >= 0; k--) {
if (k in t && t[k] === searchElement) {
return k;
}
}
return -1;
};
}
};
var MonsterInsightsObject = new MonsterInsights();