views:

200

answers:

4

Im wondering what affect loading an external page with php has on a sites analytics. If php is loading an external page, and not an actual browser, will the javascript that reports back to google analytics register the page load as a hit?

A: 

Curl will not automatically download JavaScript files the HTML refers to. So unless you explicitly download the Google Analytics JavaScript file, Google won't detect the Curl hit.

Matthew Flaschen
is there any way around this? I need to load an external page, but still have analytics work.
websiteguru
You can parse the page and explicitly have Curl download JavaScript files included within. You may also want to set the Referer header appropriately.
Matthew Flaschen
+3  A: 

Any JavaScript within the fetched page will not be run and therefore have no effect on analytics. The reason for this is that the fetched HTML page is never parsed in an actual browser, therefore, no JavaScript is executed.

webbiedave
A: 

Google offers a non-JavaScript method of tracking hits. It's intended for mobile sites, but may be repurposable for your needs.

ceejayoz
A: 

You're misunderstanding how curl/file_get_contents work. They're executed on the server, not on the client browser. As far as Google and any regular user is concerned, they'll see the output of those calls, not the calls themselves.

e.g.

  1. client requests page from server A
  2. server A requests page from server B
  3. server B replies with page data to server A
  4. server A accepts page data from server B
  5. server A sends page data to client

Assuming that all the requests work properly and don't issue any warnings/errors and there's no network glitches between server A and server B, then there is absolutely no way for the client to see exactly what server A's doing. It could be sending a local file. It could be executing a local script and send its output. It could be offshoring the request to a server in India which does the hard work and then simply claims the credit for it, etc...

Now, you CAN get the client to talk to server B directly. You could have server A spit out an HTML page that contains an iframe, image tag, script tag, css file, etc... that points to server B. But that's no longer transparent to the client - you're explicitly telling the client "hey, go over there for this content".

Marc B