I am building a tracking system for refererrals to our websites and on behalf of other 3rd party website owners. This will include placing a cookie when a customer clicks through to the site and subseqently reading their ID from this cookie if they reach the defined ‘success’ page.
I have seen a number of different methods used for tracking and they all seem to fall into 2 categories:
-
Including an IMG tag which will link to a script that processes what it needs to and returns an image
-
Including an external javascript file, usually with the same approach as in 1 within tags.
What are the benefits of one approach over the other? I feel I must be missing something quite simple here however can only see that the javascript approach can be used to avoid image caching.
The server-side script is ASP.net
EDIT: The cookie / tracking approach is being used because it seems to be the industry standard, and we need to be able to track goals over a long period of time and / or many visits however alternatvies to this approach would be welcomed!
Thanks
If you include an external script in the <head> section, it is downloaded and executed before the page is shown, so you are sure that if a user saw the page they got tracked. For <img> tags there is no such guarantee, as the user might navigate away before the browser launches the load request for that image.
So, if you want to optimize for trackability, use a <script>, but if you want to optimize for performance (no slowdown if the tracking site is slow), use an <img>.
The caching issue exists in both cases, and can be solved by sending correct headers from the server or by appending cache-busting arguments to the URL.