Script for Google Analytics (not provided)

First published on September 9, 2014 - Last updated on September 9, 2014

How to alleviate the hidden results of organic searches (not provided)


Most web administrators who are using Google Analytics to track the visitor activity on their website noticed that a lot of organic search results are not provided anymore by Google Analytics.

Google Organic Search - Not provided results This situation occured after Google transitioned to secure searches. This action is for the good of the users, since protects our right to privacy, however it also has such undesired effects.

I decided to look if I can find a way to obtain some information about the visitors that arrive to my website. At least it would be interesting to see what is the landing page and who the referer is. If the referer remains blank, it means it was a secure website (https).

Below you can see the php script. The most important information is the page name first visited, in case the referer is blank . It appends (or creates) a file on the public directory, called referers.txt.

It records the IP address of the visitor, the referer and the landing page.

    <?php
    function getUserIP()
    {
        $client  = @$_SERVER['HTTP_CLIENT_IP'];
        $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
        $remote  = $_SERVER['REMOTE_ADDR'];
        if(filter_var($client, FILTER_VALIDATE_IP))
        {
            $ip = $client;
        }
        elseif(filter_var($forward, FILTER_VALIDATE_IP))
        {
            $ip = $forward;
        }
        else
        {
            $ip = $remote;
        }
        return $ip;
    }

    $user_ip = getUserIP();
    $ref = $_SERVER['HTTP_REFERER'];
    $pageURL = $_SERVER["REQUEST_URI"];
    $remoteAddr = getUserIP();

    $file = 'referers.txt';
    $current = file_get_contents($file);
    $current .= 'IP: ' . $remoteAddr . '; Referer: ' . $ref . '; Landing Page: ' . $pageURL . "\r\n";
    file_put_contents($file, $current);
    ?>

Visitors



 


This template downloaded form free website templates