Activating google analytics using curl? - php

I need to execute a google analytics script on a site using curl. What are the reporting features that will be available to me for that curl request ?
To make my question more clearer, suppose i have a website www.abc.com which has analytics code on it and if i connect to www.abc.com from www.xyz.com using curl, in the analytics report of www.abc.com will the request i made using curl show ?
What are the parameters that wont show ? since there is no navigator there wouldnt be screen resolutions, color depth, or any other javascript based features. any other reporting features that wouldn't be available to me ?
I need the following to show up :
user agent (which i will be sending by setting header)
referrer (again which i will be sending by setting header)
source ip address and location (using proxies for different countries)
one issue that Im unsure of is Google's cookies and whether (since i might also be using proxies) these need to be cleared. The ultimate outcome is that I need to be able emulate site traffic as if it is coming from a variety of visitors....
IF the entire thing is not technically possible,is there any other way i can simulate diverse traffic into my google analytics account ?

So, the other answers are right: CURL doesn't execute JS, and there are some methods of automated requests that do.
Other methods to simulate diverse traffic to your account include:
Visit the site manually, and grab the __utm.gif request that Google Analytics generates, and manipulate its pieces so that you can CURL it in conjunction with curling the actual site, so that the GA pageviews are recorded. (ie, alter the hostname, pageview name, timestamp, etc.) You can find the meaning of the values of those parameters here.
Implement a server side GA on your target site.
Use a headless web engine to programmatically crawl sites. PhantomJS is a particularly user-friendly option.
Use a browser screenshot service like BrowserShots to get traffic from distributed locations to visit your site.
Use Amazon's Mechanical Turk to get people to visit the site. You could pay $0.01 per click, and get a large amount of diverse traffic from a large number of sources. (To verify, give them an arbitrary, simple task like asking them "What's the headline on this website?")

You can send events directly to Google Analytics using the Measurement Protocol, creating GET or POST requests directly with the tool of your choice.
See reference here:
https://developers.google.com/analytics/devguides/collection/protocol/v1/reference

No, because Google Analytics is based on Javascript and curl doesn't process HTML or Javascript.

Instead of curl, use a command-line tool that does JavaScript, like HTTPUnit (which includes Rhino). I have heard about WATIR too but never tried.
Those happen to be testing tools, but I guess you can use them to trigger Google Analytics too.

Related

Get current visitor's referrer from GA

It would be useful if, when placing an order or submitting a form, we could reliably include the visitor's referrer with the request. This is not always simple because, for example, the user could have found us via Adwords, left the site and come back by typing in the address. In this case, we would want to know the Adwords campaign for this specific visitor. Google Events don't fit well with our workflow.
Other questions have tried to use Javascript and apparently that is not possible. I noticed that Google sets a _ga cookie which we can read - it gives us an ID that looks like this: GA1.2.123456789.1234567890. Can we use PHP to extract the referrer according to Google from that ID?
Not in realtime, no. It used to be possible with the previous version of GA which evaluated traffic sources clientside and stored the values in a cookie. However with Universal Analytics the processing is now done serverside and the information is not accessible in realtime (there is a realtime API but that'S for various reasons not feasible for getting data on individual users).
It is however possible to get the referrer data via javascript - you look at document.referer and (if the referrer domain is different from your own domain) store it into a cookie (since the question is tagged with PHP, you can do the same with $_SERVER['HTTP_REFERER']).
This will not exactly match Googles info (Google will show referrals from google properties, yahoo, bing etc. not as referrer but as organic search traffic) but should be close enough.

How to mimic Google Analytics utmz-cookie creation?

Now we are using standard google analytics script dc.js to create utm-cookies by http referrer and http url of the visitor. Now google stops creating utm-cookies since Universal Analytics.
Is there any way to mimic utm-cookie creation logic by referer and url using internal or external solution?
PS. Please, don't advise to get rid of utm-cookies. The main question is: "is it possible to create cookies by the same logic which google does?"
That is not realy easy. You can use the PHP function $_SERVER ['HTTP_REFERER'] but:
The address of the page (if any) which referred the user agent to the
current page. This is set by the user agent. Not all user agents will
set this, and some provide the ability to modify HTTP_REFERER as a
feature. In short, it cannot really be trusted.
As far as I know, the Universal Analytics HAS a way of tracking referrals using _ga cookies and it works very nice. If you work with PHP (hosted GA), then you will have problems but with JavaScript woks fine.
If you whant to follow AND _utm cookies with javascript, you need to create some "push" script what will collect that data but I think Universal Analytic have that option automaticly.
Read THIS blog please.

Three Google Analytics Codes on One Site?

I was wondering if it was possible to have two or more sets of Google Analytics tracking codes on one page. There's going to be a single webpage that is accessible through either normal methods (desktop or mobile browser), or accessed through scanning the QR code on the product packaging and being redirected that way.
The client wants three things tracked:
Analytics for the full page (all methods of connection)
Analytics for just those connected via normal methods
Analytics for those connected via QR code
I have already developed a means of differentiating the connection method, and switching the Google provided Javascript for 2 and 3.
So is this possible, to have two analytics codes on one page? I have checked all over, can't find an answer that is to the point.
Thanks in advance
A single analytics will report browser and OS used and the origin of traffic. Hence, there's no reason to use three cookies, three JS files when you can just generate a personalized report with the data you need
Don't use different trackers for this, use custom variables. Splitting it up loses you valuable insight into how different use cases navigate the site.
If anyone is ever looking for this:
http://www.publicinsite.com/qr-codes-google-analytics-track-mobile-devices/
That;s the best bet I think

Sending data to the Google Analytics platform - in a pure PHP page?

I'm building an application, and I'd like to incorporate some stat tracking for each of the pages created. However, these pages are simply redirect pages using header() to different places, depending on what conditions have been met.
Rather then build my own stat tracking platform and incorporate it within PHP, I'd rather send traffic data to the Google Analytics platform. However, as the page exits via a header() alteration, I cannot print the normal Javascript code.
Is there anyway I can still have the page and query string traffic data sent to Google Analytics without using the standard script?
User's browser must make a request to Google's 1-pixel "tracking gif". There is google's solution for mobile web sites, where Javascript is not available. You can see it in the tracking code section of your google analytics settings pages. It is written for PHP. However, this pure-PHP solution just inserts <img> tag into the output. It won't work for you, since you're just making a redirect with HTTP headers.
So, there could be two solutions:
Make the redirect via META tag. Thus, you'll be able to track the redirect with either Javascript or PHP-based analytics code.
Try to fetch that 1x1 GIF from google server-side. However, this will screw lots of things in your Analytics. E.g. originating IP will be wrong, so all demographics will be wrong, you won't be able to pass cookies, etc. It will be most rudimentary tracking at best.
There's an official Google's PHP class "Server-Side Google Analytics PHP Client"
https://code.google.com/p/php-ga/

Live Analytics User data in CMS or Framework

I'm trying to use analytics to determine content being served to visitors from a CMS. As far as I can tell there is no API for Google Analytics that allows you to retrieve a users browsing history.
I understand you can store this into the users session, or roll your own logging of user visits, but I'm more interested in analytics platforms that offer and interface to access this data.
Is anyone aware of an analytics platform that allows you to programmatically retrieve the users data?
The other important aspect would be whether the user data can still be retrieved even if the storing of that data is done asynchronously - which would be needed to keep web app responsive.
In analytics platform you have several solutions. The most common in open source is Piwik http://piwik.org/
It offers an API and js tracking systems : http://piwik.org/docs/javascript-tracking/
You can set this up indirectly in Google Analytics, by using funnels and goals. Set a few predetermined paths of website pages, and have the visitors walking these paths reach a goal.
Have a look at http://www.openwebanalytics.com/. A might be a little bit of overkill for your situation, but if you need a customized need, it should be the right fit. If you're a developer or have access to one then you're set.

Categories