W
W
wartur2012-01-17 16:26:53
Google Analytics
wartur, 2012-01-17 16:26:53

Google-analytics for PHP, how to count a hit using PHP?

Hello google analytics user.

Condition:
There is a file, site.ru/file.zip, the file is relatively small - this is important for the solution . We need to count the number of jumps. The solution is obvious, put a script under the file, it gives the file and works with the counter.
UPD: It is important to understand that the download is a direct link, that is, it is impossible to intercept it with JS in this case, and if a person clicks on the link to site.ru, then this, of course, is intercepted, but we are not considering this option.

Task:
It would be nice to build a counter not in an internal database or file, but on something more global, like Google or Yandex, and display it there as a hit on a regular URL. If Yandex with ready-made libs is clearly all rotten, but there is only documentation, then I dug up a couple in Google: PHP interface for Google Analytics .

Question:
Gentlemen, either I was obviously tired by the evening, or I alone do not find anything similar to the method:
gapi::sentHitToGoogle($_SERVER);
This is a method that collects all the information received by the server and sends it to Google Analytics.

If I don't find it, then are there any adequate ones, so that it could be done not only through JS. I really don’t want to spend time on my own diving into the documentation and writing adapters for google api interfaces in PHP, if they still exist.

Thank you for your attention.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
H
homm, 2012-01-17
@wartur

Counter settings, tracking code, additionally: "Site created for mobile phones
Select the server language of your site for mobile devices."
There will be a code and a ga.php file, having figured out which you can make your request to Analytics.

H
himik, 2012-01-17
@himik

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345678-9']);
_gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

<a href="http://site.ru/file.zip" onclick="_gaq.push(['_link', 'http://site.ru/file.zip'])">Скачать</a>

or I don't understand something?

L
Lakewake, 2012-01-17
@vedmaka

why don't you consider the option with a padding from meta=refresh and js?

A
Anton, 2012-01-17
@sHinE

In Yandex, you can definitely assign a “goal” and register a handler for the file download link so that this goal is counted on click. I think that the same can be done in analytics.

J
jrip, 2012-01-17
@jrip

You can see what requests Google Analytics sends to its server, and then send the same requests. It just seems to me to be a rather strange idea. The whole advantage of such analytics is that we know what kind of person where he comes from, etc., and if using php, then in the statistics, in fact, we will see how the server downloaded files from itself.

S
Silver_Clash, 2012-01-17
@Silver_Clash

A slightly perverted version, but:
1. At the address www.example.com/file_download_here.php we put a php script that executes a request to Google Analytics, and then returns headers header('Location: www.example.com/path_to_file.zip ');
2. At the address www.example.com/path_to_file.zip there is a file by itself, but in order not to download it via a direct link, we need mod_rewrite
3. In .htaccess we write something like: Thus, it is somewhat more difficult to find out the direct path to the file. But even if someone posts a direct link to the file, all users who do not come from example.com will be sent to analytics. It remains only to take care that all links to example.com lead to www.example.com/file_download_here.php
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://www\.example\.com [NC]
RewriteRule \имя_файла.zip www.example.com/файл_качать_здесь.php [R]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question