Analysis of the source of visitors using Sourcebuster.js or where the user came to the site from / ~#root -i Analysis of the source of visitors using Sourcebuster.js or where the user came to the site from / ~#root -i Analysis of the source of visitors using Sourcebuster.js or where the user came to the site from / ~#root -i Analysis of the source of visitors using Sourcebuster.js or where the user came to the site from / ~#root -i Analysis of the source of visitors using Sourcebuster.js or where the user came to the site from / ~#root -i Analysis of the source of visitors using Sourcebuster.js or where the user came to the site from / ~#root -i Analysis of the source of visitors using Sourcebuster.js or where the user came to the site from / ~#root -i Analysis of the source of visitors using Sourcebuster.js or where the user came to the site from / ~#root -i
  • RU
  • UA
  • EN
  • Create an online store
  • Documentation
  • Blog
    • Unix ОS
    • Php
    • MySQL
    • JavaScript
    • Package Managers
    • Docker
    • Seo
  • Auxiliary services
    • Short Links
    • Exchange views YouTube
  • Sign in
  • Create Account
  • Home
  • Seo
  • Analysis of the source of visitors using Sourcebuster.js or where the user came to the site from

Analysis of the source of visitors using Sourcebuster.js or where the user came to the site from

Faced the other day with the library sourcebuster.js , I decided to tell a ready-made solution for determining the source of the visit.

I took information here . There is more detailed documentation. I will tell you a simple example of accounting and catching data.

1. Connection on the site :

In the article on the official website (the link to which is above) is given link to download the finished minified js file. It lies in the /dist directory. We will work with him. Installation via npm is also described there, but since this is a visual aid, we will omit it.

In the main template file, before the closing body tag, we connect and run the script.

<!DOCTYPE html>
<html>
<head>
...
</head>
<body>
....

<!-- sbjs analytics -->
<script src="sourcebuster.min.js"></script>
<script>
sbjs.init();
</script>
<!-- END sbjs analytics -->

</body>
</html>

To check if the added script works, type in the browser console:

sbjs.get

No error should occur and an object with information should be returned.

console_sbjs

The information that is stored in sbjs.get.current is required for us to determine the source:

sbjs.get.current

2. Work on the server side :

Sourcebuster.js works with cookies . Therefore, up-to-date information will take effect only after the page is reloaded or the user visits any other link on the site (so that the page is reloaded and the cookie is updated).

Working with data in cookies is easy.

<?php

/**
* If there is no $_COOKIE['analytic_sbjs'] then return this
*/< br />function getTempInfo() {
    $a = strtr($_COOKIE['sbjs_current'], ['|||' => '&']);
    parse_str($a, $b);
    if (!$b) {
        $b = [
            'type' => 'organic',
            'src' => 'google',
            'mdm' => 'organic',
            'cmp' => '(none)',
            'cnt' => '(none)',
            'trm' => '(none)',
        ];
    }
    return (string) json_encode($b);
}

// Extract the stored information. If it is not present in analytical_sbjs, then pull getTempInfo()
$other = strip_tags(trim((string) $_COOKIE['analitic_sbjs']) ? : getTempInfo());

/ / json_decode, and lowercase everything for easier comparison
$decode = $other ? json_decode($other, true) : [];
$decode['src'] = mb_strtolower($decode['src']);
$decode['mdm'] = mb_strtolower($decode ['mdm']);

$source = 'Other';
if ($decode['src'] == 'google' && $decode['mdm' ] == 'cpc') {
    $source = 'Google Adwords';
} elseif ($decode['src'] == 'yandex' && $decode['mdm'] == 'cpc') {
&nbsp ;   $source = 'Yandex Direct';                
} elseif (mb_stripos($decode['src'], 'youtube') !== false) {
    $source = 'Youtube';                
} elseif (in_array($decode['src'], ['facebook', 'fb']) && in_array($decode['mdm'], ['cpc','ppc ','cpa','cpm','cpv','cpp'])) {
    $source = 'Facebook ad';                
} elseif ($decode['src'] == 'instagram' && in_array($decode['mdm'], ['cpc','ppc','cpa','cpm ','cpv','cpp'])) {
    $source = 'Instagram ad';                
} elseif (mb_stripos($decode['src'], 'google') !== false && $decode['mdm'] == 'organic') {
&nbsp ;   $source = 'Google SEO';                
} elseif (mb_stripos($decode['src'], 'yandex') !== false && $decode['mdm'] == 'organic') {
&nbsp ;   $source = 'SEO Yandex';                
} elseif ($decode['src'] == 'hotline' && $decode['mdm'] == 'cpc') {
    $source = 'hotline';                
} elseif ($decode['src'] == 'priceua' && $decode['mdm'] == 'cpc') {
    $source = 'Price';                
} elseif (mb_stripos($decode['src'], 'viber') !== false) {
    $source = 'Viber';                
} elseif ((mb_stripos($decode['src'], 'facebook') !== false || mb_stripos($decode['src'], 'fb') !== false) &amp ;& !in_array($decode['mdm'], ['cpc','ppc','cpa','cpm','cpv','cpp'])) {
     $source = 'Facebook other';                
} elseif ($decode['mdm'] == 'email') {
    $source = 'Email distribution';                
} elseif ($decode['mdm'] == 'organic') {
    $source = 'SEO other';                
} elseif ($decode['mdm'] == 'cpc') {
    $source = 'Advertising other';                
} elseif ($decode['src'] == 'nadavi') {
    $source = 'Ek';                
} elseif ($decode['src'] == 'sendpulse') {
    $source = 'Send Pulse';                
} elseif (mb_stripos($decode['src'], 'yandex') !== false) {
    $source = 'Yandex other';                
} elseif ($decode['mdm'] == 'referral') {
    $source = 'Referrals from other sites';                
} elseif ($decode['src'] == '(direct)' && $decode['mdm'] == '(none)') {
 &nbsp ;  $source = 'Direct hits';                
} elseif ($decode['mdm'] == 'display') {
    $source = 'Display';                
} else {
    $source = 'Other';
}
var_dump($source); // Information about the source.

As you can see, $source will contain information about the sources from which the client switched. It is advisable to use this method when placing an order or for a similar one-time action so that it is not on the first page of the user's login.

The information is stored in $_COOKIE['analytic_sbjs'] and in $_COOKIE['sbjs_current'] (but in a specific format). The getTempInfo() function is here as insurance, suddenly the user has cookies disabled or something went wrong (whether soap). In any case, this is approximate information, as it is based on js and cookies.

I gave an example without OOP to make it more clear. I think it's more important here to sort out what comes in src and mdm , and what it means in aggregate to determine the source.

This example does not show all the features of the linked library. The rest can be found in detail on the official website, the source is given above.

13 December 18
1837
2

Comments

Игорь

16 December 2020 14:14
Не могу разобраться почему скрипт определяет перехода из поиска Яндекса тип траффика как referral, а не organic. Изменить настройки скрипта не получается.
5

root-i

16 December 2020 19:16
Игорь, скорее всего так определяет сам sourcebuster. Я привел приблизительный скрипт по обработке на бэкенде этого всего, но можно переписать под себя согласно документации http://sbjs.rocks/#/usage.
3
Name
E-mail
Rating
Review

Other articles from the category

09 June 2020

Zero Snippet or Featured Snippet, GoogleAds Response Block Diagram

Let's decide why we need a zero snippet in GoogleAds, consider the structure of the question-answer snippet. Let's give an example in html and json schema.

29 May 2018

Optimizing png images with optipng for Google Page Speed

You have to deal with png photos that are not optimized in size. There is a simple optipng optimizer that allows you to manage optimization settings.

29 May 2018

Optimizing jpg images with jpegoptim for Google Page Speed

You have to deal with jpeg photos that are not optimized in size. There is a simple jpegoptim optimizer that allows you to control optimization settings.

Categories

  • Unix OS
  • Php
  • MySQL
  • JavaScript
  • Package Managers
  • Docker
  • Seo

Latest comments

Добрый день, Сергей. Я на более новых версиях блют...
root-i
23.02.23
Пробовал на transmart колонке. Ничего из перечисле...
Сергей
20.02.23
HenryMit, может быть
root-i
07.02.23
Неофрейдизм — это… Определение, принципы, представ...
HenryMit
07.02.23

I share information in which I needed help and spent a lot of time figuring it out. If the information helped at least one person, then this site was not created in vain.

Thank you for the continuation of the site:
Contacts

Telegram Viber Mail

Search for articles

  • Sign in
  • Create Account

Powered by chmod -R