SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    any javascript to load an image..

    i have been given some conversion tracking code like so...

    <img width="1" height="1" src="http://main.tracking.com/tag.php?goal=06a15eb1c37367">

    but have been told the website i work on will only use javascript tracking code.

    my question is, is there a way of having a piece of javascript code do the same job as this code?

    i am guessing if the javascript can load this image on the page some how it will track the conversions.. i am hoping this is possible and any pointers would be great.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not familiar with what that code does, but I don't see why you would need to us JavaScript to include it for it to work. Have you tried adding it to your page to see if it works?

    If the page just tracks user visits and stats, I would recommended using Google Analytics instead.

  3. #3
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi unfortunately i can't use google and can't add this to the site. i am advertising with some other company and they only have this way to do the conversion tracking..

    <img width="1" height="1" src="http://main.tracking.com/tag.php?goal=06a15eb1c37367">

    all this does is loads an image on the page and so tracks conversions.. thats all of the code.. its very small and simple but i can't use it.

    this is an example of javascript tracking..

    <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
    </script>
    <script type="text/javascript">
    _uacct="UA-xxxx-x";
    urchinTracker();
    </script>

    just need to know if it is possible to load and image using javascript so i can get around this problem?

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I'm not really a JavaScript expert, but I would think that if all you need to do is to load the image so that the other site can register that it was loaded, then you could probably either use

    HTML Code:
    document.write('<img width="1" height="1" src="http://main.tracking.com/tag.php?goal=06a15eb1c37367" />');
    to write the image in or maybe even use an image preload script to load the image without displaying it.

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Don't use document.write, it's deprecated. You can do this:

    Code javascript:
    var img = document.createElement('img');
    img.height = img.width = 1;
    img.src = 'http://main.tracking.com/tag.php?goal=06a15eb1c37367';
    document.getElementById('wrapper').appendChild(img);
    I'm assuming you have some sort of wrapper there - change that to suit your code. Put the code at the bottom of the body, or if you already have something being loaded onload, stick it in there.

  6. #6
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi thanks i will try them.. i don't have a wrapper but hoping this will just work as is.. i am new to javascript but guess it will be..

    <script type="text/javascript">
    var img = document.createElement('img');
    img.height = img.width = 1;
    img.src = 'http://main.tracking.com/tag.php?goal=06a15eb1c37367';
    document.getElementById('wrapper').appendChild(img);
    </script>

    thanks again..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •