PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.7
Independent Analytics – WordPress Analytics Plugin v1.7
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / inc / models / referrer.php
independent-analytics / inc / models Last commit date
page.php 4 years ago page_author_archive.php 4 years ago page_date_archive.php 4 years ago page_home.php 4 years ago page_not_found.php 4 years ago page_post_type_archive.php 4 years ago page_search.php 4 years ago page_singular.php 4 years ago page_term_archive.php 4 years ago referrer.php 4 years ago
referrer.php
585 lines
1 <?php
2
3 namespace IAWP;
4
5 use IAWP\League\Uri\Uri;
6
7 class Referrer
8 {
9 private $id = null;
10 private $url = null;
11 protected $host = null;
12 protected $matched_domain = null;
13 private $name = null;
14 private $referrer_type = null;
15 protected $views;
16
17 private static $domains = [
18 'google.com' => [
19 'name' => 'Google',
20 'referrer_type' => 'Search',
21 ],
22 'google.ad' => 'google.com',
23 'google.ae' => 'google.com',
24 'google.com.af' => 'google.com',
25 'google.com.ag' => 'google.com',
26 'google.com.ai' => 'google.com',
27 'google.al' => 'google.com',
28 'google.am' => 'google.com',
29 'google.co.ao' => 'google.com',
30 'google.com.ar' => 'google.com',
31 'google.as' => 'google.com',
32 'google.at' => 'google.com',
33 'google.com.au' => 'google.com',
34 'google.az' => 'google.com',
35 'google.ba' => 'google.com',
36 'google.com.bd' => 'google.com',
37 'google.be' => 'google.com',
38 'google.bf' => 'google.com',
39 'google.bg' => 'google.com',
40 'google.com.bh' => 'google.com',
41 'google.bi' => 'google.com',
42 'google.bj' => 'google.com',
43 'google.com.bn' => 'google.com',
44 'google.com.bo' => 'google.com',
45 'google.com.br' => 'google.com',
46 'google.bs' => 'google.com',
47 'google.bt' => 'google.com',
48 'google.co.bw' => 'google.com',
49 'google.by' => 'google.com',
50 'google.com.bz' => 'google.com',
51 'google.ca' => 'google.com',
52 'google.cd' => 'google.com',
53 'google.cf' => 'google.com',
54 'google.cg' => 'google.com',
55 'google.ch' => 'google.com',
56 'google.ci' => 'google.com',
57 'google.co.ck' => 'google.com',
58 'google.cl' => 'google.com',
59 'google.cm' => 'google.com',
60 'google.cn' => 'google.com',
61 'google.com.co' => 'google.com',
62 'google.co.cr' => 'google.com',
63 'google.com.cu' => 'google.com',
64 'google.cv' => 'google.com',
65 'google.com.cy' => 'google.com',
66 'google.cz' => 'google.com',
67 'google.de' => 'google.com',
68 'google.dj' => 'google.com',
69 'google.dk' => 'google.com',
70 'google.dm' => 'google.com',
71 'google.com.do' => 'google.com',
72 'google.dz' => 'google.com',
73 'google.com.ec' => 'google.com',
74 'google.ee' => 'google.com',
75 'google.com.eg' => 'google.com',
76 'google.es' => 'google.com',
77 'google.com.et' => 'google.com',
78 'google.fi' => 'google.com',
79 'google.com.fj' => 'google.com',
80 'google.fm' => 'google.com',
81 'google.fr' => 'google.com',
82 'google.ga' => 'google.com',
83 'google.ge' => 'google.com',
84 'google.gg' => 'google.com',
85 'google.com.gh' => 'google.com',
86 'google.com.gi' => 'google.com',
87 'google.gl' => 'google.com',
88 'google.gm' => 'google.com',
89 'google.gr' => 'google.com',
90 'google.com.gt' => 'google.com',
91 'google.gy' => 'google.com',
92 'google.com.hk' => 'google.com',
93 'google.hn' => 'google.com',
94 'google.hr' => 'google.com',
95 'google.ht' => 'google.com',
96 'google.hu' => 'google.com',
97 'google.co.id' => 'google.com',
98 'google.ie' => 'google.com',
99 'google.co.il' => 'google.com',
100 'google.im' => 'google.com',
101 'google.co.in' => 'google.com',
102 'google.iq' => 'google.com',
103 'google.is' => 'google.com',
104 'google.it' => 'google.com',
105 'google.je' => 'google.com',
106 'google.com.jm' => 'google.com',
107 'google.jo' => 'google.com',
108 'google.co.jp' => 'google.com',
109 'google.co.ke' => 'google.com',
110 'google.com.kh' => 'google.com',
111 'google.ki' => 'google.com',
112 'google.kg' => 'google.com',
113 'google.co.kr' => 'google.com',
114 'google.com.kw' => 'google.com',
115 'google.kz' => 'google.com',
116 'google.la' => 'google.com',
117 'google.com.lb' => 'google.com',
118 'google.li' => 'google.com',
119 'google.lk' => 'google.com',
120 'google.co.ls' => 'google.com',
121 'google.lt' => 'google.com',
122 'google.lu' => 'google.com',
123 'google.lv' => 'google.com',
124 'google.com.ly' => 'google.com',
125 'google.co.ma' => 'google.com',
126 'google.md' => 'google.com',
127 'google.me' => 'google.com',
128 'google.mg' => 'google.com',
129 'google.mk' => 'google.com',
130 'google.ml' => 'google.com',
131 'google.com.mm' => 'google.com',
132 'google.mn' => 'google.com',
133 'google.ms' => 'google.com',
134 'google.com.mt' => 'google.com',
135 'google.mu' => 'google.com',
136 'google.mv' => 'google.com',
137 'google.mw' => 'google.com',
138 'google.com.mx' => 'google.com',
139 'google.com.my' => 'google.com',
140 'google.co.mz' => 'google.com',
141 'google.com.na' => 'google.com',
142 'google.com.ng' => 'google.com',
143 'google.com.ni' => 'google.com',
144 'google.ne' => 'google.com',
145 'google.nl' => 'google.com',
146 'google.no' => 'google.com',
147 'google.com.np' => 'google.com',
148 'google.nr' => 'google.com',
149 'google.nu' => 'google.com',
150 'google.co.nz' => 'google.com',
151 'google.com.om' => 'google.com',
152 'google.com.pa' => 'google.com',
153 'google.com.pe' => 'google.com',
154 'google.com.pg' => 'google.com',
155 'google.com.ph' => 'google.com',
156 'google.com.pk' => 'google.com',
157 'google.pl' => 'google.com',
158 'google.pn' => 'google.com',
159 'google.com.pr' => 'google.com',
160 'google.ps' => 'google.com',
161 'google.pt' => 'google.com',
162 'google.com.py' => 'google.com',
163 'google.com.qa' => 'google.com',
164 'google.ro' => 'google.com',
165 'google.ru' => 'google.com',
166 'google.rw' => 'google.com',
167 'google.com.sa' => 'google.com',
168 'google.com.sb' => 'google.com',
169 'google.sc' => 'google.com',
170 'google.se' => 'google.com',
171 'google.com.sg' => 'google.com',
172 'google.sh' => 'google.com',
173 'google.si' => 'google.com',
174 'google.sk' => 'google.com',
175 'google.com.sl' => 'google.com',
176 'google.sn' => 'google.com',
177 'google.so' => 'google.com',
178 'google.sm' => 'google.com',
179 'google.sr' => 'google.com',
180 'google.st' => 'google.com',
181 'google.com.sv' => 'google.com',
182 'google.td' => 'google.com',
183 'google.tg' => 'google.com',
184 'google.co.th' => 'google.com',
185 'google.com.tj' => 'google.com',
186 'google.tl' => 'google.com',
187 'google.tm' => 'google.com',
188 'google.tn' => 'google.com',
189 'google.to' => 'google.com',
190 'google.com.tr' => 'google.com',
191 'google.tt' => 'google.com',
192 'google.com.tw' => 'google.com',
193 'google.co.tz' => 'google.com',
194 'google.com.ua' => 'google.com',
195 'google.co.ug' => 'google.com',
196 'google.co.uk' => 'google.com',
197 'google.com.uy' => 'google.com',
198 'google.co.uz' => 'google.com',
199 'google.com.vc' => 'google.com',
200 'google.co.ve' => 'google.com',
201 'google.vg' => 'google.com',
202 'google.co.vi' => 'google.com',
203 'google.com.vn' => 'google.com',
204 'google.vu' => 'google.com',
205 'google.ws' => 'google.com',
206 'google.rs' => 'google.com',
207 'google.co.za' => 'google.com',
208 'google.co.zm' => 'google.com',
209 'google.co.zw' => 'google.com',
210 'google.cat' => 'google.com',
211 'search.yahoo.com' => [
212 'name' => 'Yahoo',
213 'referrer_type' => 'Search',
214 ],
215 'at.search.yahoo.com' => 'search.yahoo.com',
216 'be.search.yahoo.com' => 'search.yahoo.com',
217 'br.search.yahoo.com' => 'search.yahoo.com',
218 'ca.search.yahoo.com' => 'search.yahoo.com',
219 'ch.search.yahoo.com' => 'search.yahoo.com',
220 'de.search.yahoo.com' => 'search.yahoo.com',
221 'es.search.yahoo.com' => 'search.yahoo.com',
222 'espanol.search.yahoo.com' => 'search.yahoo.com',
223 'fi.search.yahoo.com' => 'search.yahoo.com',
224 'fr.search.yahoo.com' => 'search.yahoo.com',
225 'gr.search.yahoo.com' => 'search.yahoo.com',
226 'hk.search.yahoo.com' => 'search.yahoo.com',
227 'id.search.yahoo.com' => 'search.yahoo.com',
228 'ie.search.yahoo.com' => 'search.yahoo.com',
229 'il.search.yahoo.com' => 'search.yahoo.com',
230 'in.search.yahoo.com' => 'search.yahoo.com',
231 'it.search.yahoo.com' => 'search.yahoo.com',
232 'malaysia.search.yahoo.com' => 'search.yahoo.com',
233 'nl.search.yahoo.com' => 'search.yahoo.com',
234 'no.search.yahoo.com' => 'search.yahoo.com',
235 'ph.search.yahoo.com' => 'search.yahoo.com',
236 'pl.search.yahoo.com' => 'search.yahoo.com',
237 'qc.search.yahoo.com' => 'search.yahoo.com',
238 'ro.search.yahoo.com' => 'search.yahoo.com',
239 'ru.search.yahoo.com' => 'search.yahoo.com',
240 'se.search.yahoo.com' => 'search.yahoo.com',
241 'sg.search.yahoo.com' => 'search.yahoo.com',
242 'tr.search.yahoo.com' => 'search.yahoo.com',
243 'tw.search.yahoo.com' => 'search.yahoo.com',
244 'ua.search.yahoo.com' => 'search.yahoo.com',
245 'uk.search.yahoo.com' => 'search.yahoo.com',
246 'vn.search.yahoo.com' => 'search.yahoo.com',
247 'za.search.yahoo.com' => 'search.yahoo.com',
248 'uk.search.yahoo.com' => 'search.yahoo.com',
249 'bing.com' => [
250 'name' => 'Bing',
251 'referrer_type' => 'Search',
252 ],
253 'yandex.com' => [
254 'name' => 'Yandex',
255 'referrer_type' => 'Search',
256 ],
257 'yandex.ru' => 'yandex.com',
258 'yandex.ua' => 'yandex.com',
259 'yandex.by' => 'yandex.com',
260 'yandex.kz' => 'yandex.com',
261 'yandex.uz' => 'yandex.com',
262 'yandex.com.tr' => 'yandex.com',
263 'yandex.fr' => 'yandex.com',
264 'yandex.az' => 'yandex.com',
265 'yandex.com.ge' => 'yandex.com',
266 'yandex.com.am' => 'yandex.com',
267 'yandex.co.il' => 'yandex.com',
268 'yandex.lv' => 'yandex.com',
269 'yandex.lt' => 'yandex.com',
270 'yandex.ee' => 'yandex.com',
271 'yandex.md' => 'yandex.com',
272 'yandex.tm' => 'yandex.com',
273 'yandex.tj' => 'yandex.com',
274 'duckduckgo.com' => [
275 'name' => 'DuckDuckGo',
276 'referrer_type' => 'Search',
277 ],
278 'ecosia.org' => [
279 'name' => 'Ecosia',
280 'referrer_type' => 'Search',
281 ],
282 'qwant.com' => [
283 'name' => 'Qwant',
284 'referrer_type' => 'Search',
285 ],
286 'alohafind.com' => [
287 'name' => 'AlohaFind',
288 'referrer_type' => 'Search',
289 ],
290 'twitter.com' => [
291 'name' => 'Twitter',
292 'referrer_type' => 'Social',
293 ],
294 'facebook.com' => [
295 'name' => 'Facebook',
296 'referrer_type' => 'Social',
297 ],
298 'm.facebook.com' => 'facebook.com',
299 'instagram.com' => [
300 'name' => 'Instagram',
301 'referrer_type' => 'Social',
302 ],
303 'tiktok.com' => [
304 'name' => 'TikTok',
305 'referrer_type' => 'Social',
306 ],
307 'linkedin.com' => [
308 'name' => 'LinkedIn',
309 'referrer_type' => 'Social',
310 ],
311 'pinterest.com' => [
312 'name' => 'Pinterest',
313 'referrer_type' => 'Social',
314 ],
315 'youtube.com' => [
316 'name' => 'YouTube',
317 'referrer_type' => 'Social',
318 ],
319 'artstation.com' => [
320 'name' => 'ArtStation',
321 'referrer_type' => 'Social',
322 ],
323 'bandcamp.com' => [
324 'name' => 'Bandcamp',
325 'referrer_type' => 'Social',
326 ],
327 'behance.net' => [
328 'name' => 'Behance',
329 'referrer_type' => 'Social',
330 ],
331 'bitbucket.org' => [
332 'name' => 'Bitbucket',
333 'referrer_type' => 'Social',
334 ],
335 'codepen.io' => [
336 'name' => 'CodePen',
337 'referrer_type' => 'Social',
338 ],
339 'deviantart.com' => [
340 'name' => 'DeviantArt',
341 'referrer_type' => 'Social',
342 ],
343 'discord.com' => [
344 'name' => 'Discord',
345 'referrer_type' => 'Social',
346 ],
347 'dribbble.com' => [
348 'name' => 'Dribble',
349 'referrer_type' => 'Social',
350 ],
351 'flickr.com' => [
352 'name' => 'Flickr',
353 'referrer_type' => 'Social',
354 ],
355 'github.com' => [
356 'name' => 'GitHub',
357 'referrer_type' => 'Social',
358 ],
359 'goodreads.com' => [
360 'name' => 'Goodreads',
361 'referrer_type' => 'Social',
362 ],
363 'news.ycombinator.com' => [
364 'name' => 'Hacker News',
365 'referrer_type' => 'Social',
366 ],
367 'meetup.com' => [
368 'name' => 'Meetup',
369 'referrer_type' => 'Social',
370 ],
371 'mixcloud.com' => [
372 'name' => 'Mixcloud',
373 'referrer_type' => 'Social',
374 ],
375 'patreon.com' => [
376 'name' => 'Patreon',
377 'referrer_type' => 'Social',
378 ],
379 'quora.com' => [
380 'name' => 'Quora',
381 'referrer_type' => 'Social',
382 ],
383 'qq.com' => [
384 'name' => 'Tencent QQ',
385 'referrer_type' => 'Social',
386 ],
387 'ravelry.com' => [
388 'name' => 'Ravelry',
389 'referrer_type' => 'Social',
390 ],
391 'reddit.com' => [
392 'name' => 'Reddit',
393 'referrer_type' => 'Social',
394 ],
395 'slack.com' => [
396 'name' => 'Slack',
397 'referrer_type' => 'Social',
398 ],
399 'slideshare.net' => [
400 'name' => 'SlideShare',
401 'referrer_type' => 'Social',
402 ],
403 'snapchat.com' => [
404 'name' => 'Snapchat',
405 'referrer_type' => 'Social',
406 ],
407 'soundcloud.com' => [
408 'name' => 'SoundCloud',
409 'referrer_type' => 'Social',
410 ],
411 'stackoverflow.com' => [
412 'name' => 'Stack Overflow',
413 'referrer_type' => 'Social',
414 ],
415 'stumbleupon.com' => [
416 'name' => 'StumbleUpon',
417 'referrer_type' => 'Social',
418 ],
419 'telegram.org' => [
420 'name' => 'Telegram',
421 'referrer_type' => 'Social',
422 ],
423 'weibo.com' => [
424 'name' => 'Weibo',
425 'referrer_type' => 'Social',
426 ],
427 'tumblr.com' => [
428 'name' => 'Tumblr',
429 'referrer_type' => 'Social',
430 ],
431 'twitch.tv' => [
432 'name' => 'Twitch',
433 'referrer_type' => 'Social',
434 ],
435 'vimeo.com' => [
436 'name' => 'Vimeo',
437 'referrer_type' => 'Social',
438 ],
439 'wechat.com' => [
440 'name' => 'WeChat',
441 'referrer_type' => 'Social',
442 ],
443 'whatsapp.com' => [
444 'name' => 'WhatsApp',
445 'referrer_type' => 'Social',
446 ],
447 '500px.com' => [
448 'name' => '500px',
449 'referrer_type' => 'Social',
450 ],
451 ];
452
453 public function __construct($id, $url, $views, $visitors)
454 {
455 $this->id = $id;
456 $this->views = $views;
457 $this->visitors = $visitors;
458
459 $components = Uri::createFromString($url ?? '');
460 $host = $components->getHost();
461
462 if (!is_null($host)) {
463 $this->url = $url;
464 $this->host = $host;
465 $this->populate_domain_data();
466 }
467 }
468
469 private function populate_domain_data($host = null)
470 {
471 $host = $host ?? $this->host;
472 $matched_domain = null;
473 $data = null;
474
475 foreach (self::$domains as $key => $value) {
476 if (str_ends_with($host, $key)) {
477 $matched_domain = $key;
478 $data = $value;
479 break;
480 }
481 }
482
483 if (is_array($data)) {
484 $this->url = 'https://' . $host;
485 $this->host = $host;
486 $this->matched_domain = $matched_domain;
487 $this->name = $data['name'];
488 $this->referrer_type = $data['referrer_type'];
489 } elseif (is_string($data)) {
490 $this->populate_domain_data($data);
491 } else {
492 return null;
493 }
494 }
495
496 public function id()
497 {
498 return $this->id;
499 }
500
501 public function referrer_name()
502 {
503 if (!is_null($this->name)) {
504 return $this->name;
505 } elseif (!is_null($this->host)) {
506 if (str_starts_with($this->host, 'www.')) {
507 return substr($this->host, 4);
508 }
509
510 return $this->host;
511 }
512 }
513
514 public function referrer()
515 {
516 if (!is_null($this->url)) {
517 return $this->url;
518 } else {
519 return 'Direct';
520 }
521 }
522
523 public function referrer_type()
524 {
525 if (!is_null($this->referrer_type)) {
526 return $this->referrer_type;
527 } elseif (!is_null($this->host)) {
528 return 'Referrer';
529 } else {
530 return 'Direct';
531 }
532 }
533
534 public function views()
535 {
536 return $this->views;
537 }
538
539 public function visitors()
540 {
541 return $this->visitors;
542 }
543
544 public function is_direct()
545 {
546 return !$this->is_referrer();
547 }
548
549 public function is_referrer()
550 {
551 return !is_null($this->url);
552 }
553
554 public static function merge($referrers)
555 {
556 $merged_referrers = [];
557
558 foreach ($referrers as $referrer) {
559 $match = false;
560
561 foreach ($merged_referrers as $potential_match) {
562 if (!is_null($referrer->matched_domain) && !is_null($potential_match->matched_domain) && $referrer->matched_domain == $potential_match->matched_domain) {
563 $match = true;
564 $potential_match->views += $referrer->views;
565 $potential_match->visitors += $referrer->visitors;
566 }
567 }
568
569 if ($match == false) {
570 $merged_referrers[] = $referrer;
571 }
572 }
573
574 usort($merged_referrers, function ($a, $b) {
575 if ($a->views == $b->views) {
576 return 0;
577 } else {
578 return ($a->views < $b->views) ? 1 : -1;
579 }
580 });
581
582 return $merged_referrers;
583 }
584 }
585