pixel tracking : retrieving the parameters sent through url via <img src=""/> on server side

647 Views Asked by At

I am trying to create a pixel tracker using javascript, and have included the necessary parameters in the url and have included this:

img src="/Documents/myimg.gif?utm_source="myfile"

now, I am unable to understand how to access the parameters on the servlet using java. Could someone help me with this??

1

There are 1 best solutions below

0
Martin Chuka On

I don't have a solid knowledge of java servlet but i believe the same idea will work.

In PHP i would just create a directory with a script that return the content type image/* so for instance

/Document/index.php with the following content

    <?php 

    $getVar=$_GET;

    // do the necessary with the get vars
    header('Content-Type:image/jpg');// you can adjust the content type accordingly

    /* this is the image url. you can use 
    .htaccess and get this as the last parameter of the url just like in your question */
    readfile('myimg.gif');

To make the url just like what you have currently - .htaccess will help to rewrite the url to look pretty much like anything, even take multiple images/actions with switch statement or if on the back-end

<img src="/Documents/myimg.gif?utm_source="myfile"/>

Again this is for PHP but you should get an idea.