3 Replies Latest reply: Dec 4, 2012 4:02 AM by user516929 RSS

    Google Analytics in ADF using javascript

    867506
      Hi,

      I am trying to use the Google Analytics in my application, for that I embedded a piece of javascript under af:document tag

      <af:resource type="javascript">
      var gaq = gaq || [];
      gaq.push(['setAccount','UA-30968558-1' ]);
      gaq.push(['trackPageview']);(function () { var ga =
      document.createElement('script'); ga.type =
      'text/javascript'; ga.async = true; ga.src = ('https:' ==
      document.location.protocol ? 'https://ssl' : 'http://www') +
      '.google-analytics.com/ga.js'; var s =
      document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(ga, s); })();
      </af:resource>

      The Google Analytic Id varies per instance so I created a view object to get the google analytics id. Instead of hard coding the Id I want to dynamically bind the value.


      I tried the following
      <af:resource type="javascript">
      var gaq = gaq || [];
      var gaId;
      gaId = document.getElementById("gaId");
      gaq.push(['setAccount','gaId' ]);
      gaq.push(['trackPageview']);(function () { var ga =
      document.createElement('script'); ga.type =
      'text/javascript'; ga.async = true; ga.src = ('https:' ==
      document.location.protocol ? 'https://ssl' : 'http://www') +
      '.google-analytics.com/ga.js'; var s =
      document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(ga, s); })();
      </af:resource>

      <af:inputText value="#{bindings.Googleanalyticsid.inputValue}"
      id="gaId"
      contentStyle="100%" visible="false">
      </af:inputText>

      For some reason the page is not displaying correctly.


      Could anyone help me out.
        • 1. Re: Google Analytics in ADF using javascript
          867506
          an update on this.

          I used firebug watch to see the value in document.getElementById(gaId), in the textContent field I was able to see the value which I wanted(google analytics id)
          So I modified the code

          <af:resource type="javascript">
          var gaq = gaq || [];
          gaq.push(['setAccount',document.getElementById("gaId").textContent ]);
          gaq.push(['trackPageview']);(function () { var ga =
          document.createElement('script'); ga.type =
          'text/javascript'; ga.async = true; ga.src = ('https:' ==
          document.location.protocol ? 'https://ssl' : 'http://www') +
          '.google-analytics.com/ga.js'; var s =
          document.getElementsByTagName('script')[0];
          s.parentNode.insertBefore(ga, s); })();
          </af:resource>

          Still in the firebug I could see the value but the number of users hitting the page is not changing.

          Could anyone put some light on it.

          Thanks a lot!!!

          Edited by: user13514455 on Apr 23, 2012 7:34 AM
          • 2. Re: Google Analytics in ADF using javascript
            user516929
            Hey!! I am also stuck with similar issue .Did you get an answer to it??
            • 3. Re: Google Analytics in ADF using javascript
              user516929
              I too got stuck in similar issue . Do you get the solution ?