Home » Php » php – Activating google analytics using curl?

php – Activating google analytics using curl?

Posted by: admin July 12, 2020 Leave a comment


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 ?

How to&Answers:

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:


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.