benhowdle89
benhowdle89

Reputation: 37464

Tracking requests on a CDN file

I have spoken to a well known hosting company about tracking requests to a CDN file, they do not offer this.

What i want to do is allow the user to upload a CSS file/pure CSS, take this file or raw CSS and put it into the CDN, i then will give the user a unique link to their file, so they can do something like <link rel="stylesheet" href="http://myCDN.com/uniquelink.css"> and for the file to be outputted as valid CSS. This is relatively simple, but i need to track how many requests are made to the file for charging purposes. How can i do this without getting them to go through a PHP script first (which defeats the object of giving them a speedy CDN link)?

Any advice welcome.

Upvotes: 1

Views: 993

Answers (3)

EPB
EPB

Reputation: 4029

I'm gunna have to agree with Blair McMillan, your best bet is to find a CDN that'll let you check access logs.

Though if that's really not an option, something you could try is CSS's @import feature. At the top of your CSS, add @import url("http://host.example.com/path-to-tracking-script.php?id=383"); And that should trigger a request to your tracking script. (You'll obviously not be able to get the HTTP REFERER if you're after that. [edit: since it'll always be your CSS file, not the page that loaded the css file]) Though I'm not aware of what kind of affect that might have on load performance, but it might be worth testing if you don't want to change CDNs.

Upvotes: 1

pleasedontbelong
pleasedontbelong

Reputation: 20102

instead of giving the real link to the user, create a page on your server that logs the request and then redirects to the real link.

An example:

user loads a css file to the CDN and the CDN gives you the link:

www.myCDN.com/?id=123

instead of giving this url directly to your user, you could give him something like:

www.mysite.com/track_css.php?url=www.myCDN.com%2F%3Fid%3D123

or if you want to, you could save the CDN link into a Database and identify it using an id, so the url would be something like

www.mysite.com/track_css.php?file_id=123

In the track_css.php you can save any information you want (IP's, date, user-agent, etc) and after, redirect to the real file in the cdn... or maybe retreive the content and display it directly

Hope this helps

EDIT: Didn't see the "without getting them to go through a PHP script first", =P so, never mind

Upvotes: 0

Blair McMillan
Blair McMillan

Reputation: 5349

If you rule out intermediate scripts that you control then I believe your only option is using normal stats that read the server logs. Meaning that you (or someone here might know of one) need to find a CDN provider that does support tracking (or web stats that you can access).

Upvotes: 1

Related Questions