Any javascript experts ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fluffygrrl
    So Fucking Banned
    • May 2006
    • 2187

    #1

    Any javascript experts ?

    I have an issue with tracking clicks via google analytics.

    Here's the google tracking code :

    Code:
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("&#37;3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-xxxxxx-x");
    pageTracker._initData();
    pageTracker._trackPageview();
    </script>
    Here's my homegrown effort at tracking clicks to iframes :

    Code:
    <script type="text/javascript">
    function trackLC(){  pageTracker._trackPageview('/G3/LC.html');}
    
    var elements;
    
    if(document.getElementsByTagName) {
    	elements = document.body.getElementsByTagName("IFRAME");
    } else if (document.body.all) {
    	elements = document.body.all.tags("IFRAME");
    } else {
      elements = array();
    }
    for(var i = 0; i < elements.length; i++) {
    if(elements[i].src.indexOf("xxxblackbook.com") > -1) {
    elements[i].onfocus = trackLC;
    }
    }
    Now in theory, this script should call the function whenever it sees the sponsor's domain, and the function should increment the goal hits for google analytics.

    It is however not werking. Anyone can spot the bug ? My eyes are crossing already.
  • fluffygrrl
    So Fucking Banned
    • May 2006
    • 2187

    #2
    Anybody ?

    Comment

    • StuartD
      Sofa King Band
      • Jul 2002
      • 29903

      #3
      Your code looks fine but I don't know enough about google's code to know if that's the proper way to pass along page information to it.
      This is me on facebook
      This is me on twitter

      Comment

      • fluffygrrl
        So Fucking Banned
        • May 2006
        • 2187

        #4
        Well fuck me, I've read the thing 500 times, I still got no clue what's going wrong.

        However, this

        Code:
        <a href="url here" onClick="javascript: pageTracker._trackPageview('track page here');">anchor</a>
        Works as expected.

        Comment

        • fluffygrrl
          So Fucking Banned
          • May 2006
          • 2187

          #5
          Bump for this, you never know.

          Comment

          • fluffygrrl
            So Fucking Banned
            • May 2006
            • 2187

            #6
            Final bump.

            Comment

            • Dvae
              Confirmed User
              • Feb 2005
              • 5326

              #7
              I have a feeling this may have something to do with crossframe scripting and security.
              http://msdn2.microsoft.com/en-us/lib...28(VS.85).aspx

              Second, what errors are you getting?

              Do you have the error console installed? If you do this should give you at least a hint what the problem may be.
              The error console is a Firefox addon, don't know about IE.
              Firebug is also a good addon.
              .
              .

              Arguing with a troll is a lot like wrestling in the mud with a pig, after a couple of hours you realize the pig likes it.

              Comment

              • fluffygrrl
                So Fucking Banned
                • May 2006
                • 2187

                #8
                There's no javascript errors at all.

                In principle, there shouldn't be a xfs issue, seeing how my script does not write anything at all, it merely reads iframed content and then calls a function. Where do you see the issue ?

                Comment

                • Dvae
                  Confirmed User
                  • Feb 2005
                  • 5326

                  #9
                  Where do you see the issue ?
                  I would need a more complete example or link where you have it set up to be able to tell.
                  .
                  .

                  Arguing with a troll is a lot like wrestling in the mud with a pig, after a couple of hours you realize the pig likes it.

                  Comment

                  • fluffygrrl
                    So Fucking Banned
                    • May 2006
                    • 2187

                    #10
                    Say http://lolcunts.com

                    Comment

                    • Dvae
                      Confirmed User
                      • Feb 2005
                      • 5326

                      #11
                      Originally posted by fluffygrrl
                      First thing is since you have your script in the body it gets called as it loads. and you have the iframe loading after the script runs.
                      Try flip-flopping that.
                      I got a different result when I ran it that way.

                      This could be put in the head tags then use an onload call in the body tags.
                      Also you can add some alerts like so:
                      Code:
                      function trackLC(){
                      pageTracker._trackPageview('/G3/LC.html');
                      
                      }
                      
                      var elements;
                      if(document.getElementsByTagName) {
                      	elements = document.body.getElementsByTagName("IFRAME");
                      alert("if" +elements)
                      	
                      }
                      else if (document.body.all) {
                      alert("else if")
                      	elements = document.body.all.tags("IFRAME");
                      } else {
                      alert("else")
                        elements = array();
                      }
                      alert("b4 for")
                      for(var i = 0; i < elements.length; i++) {
                      alert("for"+elements[i])
                      if(elements[i].src.indexOf("xxxblackbook.com") > -1) {
                      alert("for in if  elements"+elements[i])
                      elements[i].onfocus = trackLC;
                      }
                      }
                      In this way you can step through it and get some feedback.

                      Other than that I would need to have a way to know if its working such as the log file (I'm assuming its writing to)
                      Last edited by Dvae; 04-17-2008, 11:40 AM.
                      .
                      .

                      Arguing with a troll is a lot like wrestling in the mud with a pig, after a couple of hours you realize the pig likes it.

                      Comment

                      Working...