T5: Include Google Analytics Code

View: New views
9 Messages — Rating Filter:   Alert me  

T5: Include Google Analytics Code

by moritzgilsdorf-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I have a problem with using Google Analytics in my project. I've added the
GA scripts in my Layout.tml just before the closing body tag. When rendering
the Page, Tapestry inserts between the GA scripts and the </body> the
following code:

<script type="text/javascript">
<!--
Tapestry.onDOMLoaded(function() {
$('gene').activate();
Tapestry.init({"validate":[["organism",[["required","You must provide a
value for Organism."]]]]});
});
// -->

I suspect this behavior to cause GA to fail. Does anyone has a similar
problem or knows a quick workaround to solve this?

Thanks in advance!

Moritz
--
View this message in context: http://n2.nabble.com/T5%3A-Include-Google-Analytics-Code-tp3200824p3200824.html
Sent from the Tapestry Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: T5: Include Google Analytics Code

by Sergey Didenko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

May be it's related to these javascript bugs:

http://www.nabble.com/-T5.1.0.5--%27Tapestry%27-is-undefined-JavaScript-error-on-form-submit-tp23834056p23839494.html

"TAP-712: Form component: javascript error in IE when submitting form"
- Strange, I can't find this discussion on nabble, the summary is
"

Check the logs, I assume there will be some errors.
I had similar problems but these were solved once using the following settings :

-Dtapestry.combine-scripts=false -Dtapestry.gzip-compression-enabled=false

when I start the application (you could also contribute these values).

I am not sure you need both, quite possibly turning off gzip
compression is enough (there was some gzip related error in
"

thanks to Joachim Van der Auwera.

On Fri, Jul 3, 2009 at 2:50 PM, moritzgilsdorf<moritz.gilsdorf@...> wrote:

>
> Hi,
>
> I have a problem with using Google Analytics in my project. I've added the
> GA scripts in my Layout.tml just before the closing body tag. When rendering
> the Page, Tapestry inserts between the GA scripts and the </body> the
> following code:
>
> <script type="text/javascript">
> <!--
> Tapestry.onDOMLoaded(function() {
> $('gene').activate();
> Tapestry.init({"validate":[["organism",[["required","You must provide a
> value for Organism."]]]]});
> });
> // -->
>
> I suspect this behavior to cause GA to fail. Does anyone has a similar
> problem or knows a quick workaround to solve this?
>
> Thanks in advance!
>
> Moritz
> --
> View this message in context: http://n2.nabble.com/T5%3A-Include-Google-Analytics-Code-tp3200824p3200824.html
> Sent from the Tapestry Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: T5: Include Google Analytics Code

by moritzgilsdorf-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks, but that didn't solved the problem.

The Google Analytics instructions say that I have to insert the tracking
code "...immediately before the </body> tag of each page you are planning to
track". So the problem is simply that Tapestry is inserting his Script as
the last script before the </body> tag.

I hope somone here can suggest a simple workaround for this problem.



Sergey Didenko wrote:

>
> May be it's related to these javascript bugs:
>
> http://www.nabble.com/-T5.1.0.5--%27Tapestry%27-is-undefined-JavaScript-error-on-form-submit-tp23834056p23839494.html
>
> "TAP-712: Form component: javascript error in IE when submitting form"
> - Strange, I can't find this discussion on nabble, the summary is
> "
>
> Check the logs, I assume there will be some errors.
> I had similar problems but these were solved once using the following
> settings :
>
> -Dtapestry.combine-scripts=false -Dtapestry.gzip-compression-enabled=false
>
> when I start the application (you could also contribute these values).
>
> I am not sure you need both, quite possibly turning off gzip
> compression is enough (there was some gzip related error in
> "
>
> thanks to Joachim Van der Auwera.
>
> On Fri, Jul 3, 2009 at 2:50 PM, moritzgilsdorf<moritz.gilsdorf@...>
> wrote:
>>
>> Hi,
>>
>> I have a problem with using Google Analytics in my project. I've added
>> the
>> GA scripts in my Layout.tml just before the closing body tag. When
>> rendering
>> the Page, Tapestry inserts between the GA scripts and the </body> the
>> following code:
>>
>> <script type="text/javascript">
>> <!--
>> Tapestry.onDOMLoaded(function() {
>> $('gene').activate();
>> Tapestry.init({"validate":[["organism",[["required","You must provide a
>> value for Organism."]]]]});
>> });
>> // -->
>>
>> I suspect this behavior to cause GA to fail. Does anyone has a similar
>> problem or knows a quick workaround to solve this?
>>
>> Thanks in advance!
>>
>> Moritz
>> --
>> View this message in context:
>> http://n2.nabble.com/T5%3A-Include-Google-Analytics-Code-tp3200824p3200824.html
>> Sent from the Tapestry Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>
>

--
View this message in context: http://n2.nabble.com/T5%3A-Include-Google-Analytics-Code-tp3200824p3340940.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: T5: Include Google Analytics Code

by Harald Geritzer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


hello,

i wrote some custom component for one of my projects. it's included just before the closing body tag.

        <body>
                ...

                <span t:type="GoogleTracker" trackerId="XXXXXXX" />
        </body>


GoogleTracker.java
==================

public class GoogleTracker {

        @Paramter
        private String trackerId;
       

        public String getTrackerId() {
                return trackerId;
        }
}


GoogleTracker.tml
=================

<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<script type="text/javascript">
        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
        document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'
type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
        if (typeof(_gat) == 'object') {
                var pageTracker = _gat._getTracker("${trackerId}");
                pageTracker._initData();
                pageTracker._trackPageview();
        }
</script>
</t:container>

moritzgilsdorf schrieb:

> Hi,
>
> I have a problem with using Google Analytics in my project. I've added the
> GA scripts in my Layout.tml just before the closing body tag. When rendering
> the Page, Tapestry inserts between the GA scripts and the </body> the
> following code:
>
> <script type="text/javascript">
> <!--
> Tapestry.onDOMLoaded(function() {
> $('gene').activate();
> Tapestry.init({"validate":[["organism",[["required","You must provide a
> value for Organism."]]]]});
> });
> // -->
>
> I suspect this behavior to cause GA to fail. Does anyone has a similar
> problem or knows a quick workaround to solve this?
>
> Thanks in advance!
>
> Moritz


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: T5: Include Google Analytics Code

by moritzgilsdorf-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I tried it but it still inserts the tapestry-code after the GA code and
before the </body> tag.

Any other suggestions?



Harald Geritzer wrote:

>
>
> hello,
>
> i wrote some custom component for one of my projects. it's included just
> before the closing body tag.
>
> <body>
> ...
>
>
> </body>
>
>
> GoogleTracker.java
> ==================
>
> public class GoogleTracker {
>
> @Paramter
> private String trackerId;
>
>
> public String getTrackerId() {
> return trackerId;
> }
> }
>
>
> GoogleTracker.tml
> =================
>
> <t:container
> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
> <script type="text/javascript">
> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl."
> : "http://www.");
> document.write(unescape("%3Cscript src='" + gaJsHost +
> "google-analytics.com/ga.js'
> type='text/javascript'%3E%3C/script%3E"));
> </script>
> <script type="text/javascript">
> if (typeof(_gat) == 'object') {
> var pageTracker = _gat._getTracker("${trackerId}");
> pageTracker._initData();
> pageTracker._trackPageview();
> }
> </script>
> </t:container>
>
> moritzgilsdorf schrieb:
>> Hi,
>>
>> I have a problem with using Google Analytics in my project. I've added
>> the
>> GA scripts in my Layout.tml just before the closing body tag. When
>> rendering
>> the Page, Tapestry inserts between the GA scripts and the </body> the
>> following code:
>>
>> <script type="text/javascript">
>> <!--
>> Tapestry.onDOMLoaded(function() {
>> $('gene').activate();
>> Tapestry.init({"validate":[["organism",[["required","You must provide a
>> value for Organism."]]]]});
>> });
>> // -->
>>
>> I suspect this behavior to cause GA to fail. Does anyone has a similar
>> problem or knows a quick workaround to solve this?
>>
>> Thanks in advance!
>>
>> Moritz
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>
>

--
View this message in context: http://n2.nabble.com/T5%3A-Include-Google-Analytics-Code-tp3200824p3341390.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: T5: Include Google Analytics Code

by Jérôme BERNARD :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Eventually this might help.
Add in your module class:
public void
contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter>
configuration,
                                         @Symbol(value =
"tapestry.production-mode") boolean productionMode,
                                         @Path(value =
"${tapestry.default-stylesheet}") Asset stylesheetAsset,
                                         @Path(value =
"${tapestry.spacer-image}") Asset spacerImage,
                                         ValidationMessagesSource
validationMessagesSource,
                                         SymbolSource symbolSource,
AssetSource assetSource,
                                         @Inject @Symbol("
google.analytics.id") final String googleAnalyticsID) {
        if (productionMode)
            configuration.add("GoogleAnalytics", new
GoogleAnalyticsMarkupRenderer(googleAnalyticsID));
    }

With the following class:
public class GoogleAnalyticsMarkupRenderer implements MarkupRendererFilter {
    private String siteID;

    public GoogleAnalyticsMarkupRenderer(String siteID) {
        this.siteID = siteID;
    }

    public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
        renderer.renderMarkup(writer);
        String analytics = "<script type='text/javascript'>\n" +
            "  var gaJsHost = (('https:' == document.location.protocol) ? '
https://ssl.' : 'http://www.');\n" +
            "  document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"
google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n" +
            "</script>\n" +
            "<script type='text/javascript'>\n" +
            "  var pageTracker = _gat._getTracker('" + siteID + "');\n" +
            "  pageTracker._trackPageview();\n" +
            "</script>\n";
        Element root = writer.getDocument().getRootElement();
        Element body = root.find("body");
        body.raw(analytics);
    }
}

On Tue, Jul 28, 2009 at 12:27, moritzgilsdorf <moritz.gilsdorf@...>wrote:

>
> I tried it but it still inserts the tapestry-code after the GA code and
> before the </body> tag.
>
> Any other suggestions?
>
>
>
> Harald Geritzer wrote:
> >
> >
> > hello,
> >
> > i wrote some custom component for one of my projects. it's included just
> > before the closing body tag.
> >
> >       <body>
> >               ...
> >
> >
> >       </body>
> >
> >
> > GoogleTracker.java
> > ==================
> >
> > public class GoogleTracker {
> >
> >       @Paramter
> >       private String trackerId;
> >
> >
> >       public String getTrackerId() {
> >               return trackerId;
> >       }
> > }
> >
> >
> > GoogleTracker.tml
> > =================
> >
> > <t:container
> > xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
> > <script type="text/javascript">
> >       var gaJsHost = (("https:" == document.location.protocol) ? "
> https://ssl."
> > : "http://www.");
> >       document.write(unescape("%3Cscript src='" + gaJsHost +
> > "google-analytics.com/ga.js'
> > type='text/javascript'%3E%3C/script%3E"));
> > </script>
> > <script type="text/javascript">
> >       if (typeof(_gat) == 'object') {
> >               var pageTracker = _gat._getTracker("${trackerId}");
> >               pageTracker._initData();
> >               pageTracker._trackPageview();
> >       }
> > </script>
> > </t:container>
> >
> > moritzgilsdorf schrieb:
> >> Hi,
> >>
> >> I have a problem with using Google Analytics in my project. I've added
> >> the
> >> GA scripts in my Layout.tml just before the closing body tag. When
> >> rendering
> >> the Page, Tapestry inserts between the GA scripts and the </body> the
> >> following code:
> >>
> >> <script type="text/javascript">
> >> <!--
> >> Tapestry.onDOMLoaded(function() {
> >> $('gene').activate();
> >> Tapestry.init({"validate":[["organism",[["required","You must provide a
> >> value for Organism."]]]]});
> >> });
> >> // -->
> >>
> >> I suspect this behavior to cause GA to fail. Does anyone has a similar
> >> problem or knows a quick workaround to solve this?
> >>
> >> Thanks in advance!
> >>
> >> Moritz
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@...
> > For additional commands, e-mail: users-help@...
> >
> >
> >
>
> --
> View this message in context:
> http://n2.nabble.com/T5%3A-Include-Google-Analytics-Code-tp3200824p3341390.html
> Sent from the Tapestry Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>


--
Jerome Bernard,
Director, EMEA Operations,
Elastic Grid, LLC.
Site: http://www.elastic-grid.com
Blog: http://blog.elastic-grid.com

Re: T5: Include Google Analytics Code

by Fernando Padilla :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The google code doesn't HAVE to be the last thing on the page.  It will
work anywhere on the page.  You can bring in the js file normally
through tapestry's addScriptLink (or IncludeJavascript annotation), and
then add the google code through addScript..

it would be something like below, but you have to learn how to deal with
tapestry javascript and renderSupport properly. :)



renderSupport.addScriptLink("http://www.google-analytics.com/ga.js");
renderSupport.addScript( "if (typeof(_gat) == 'object') {var pageTracker
=
_gat._getTracker("${trackerId}");pageTracker._initData();pageTracker._trackPageview();}"
);



On 7/28/09 3:27 AM, moritzgilsdorf wrote:

> I tried it but it still inserts the tapestry-code after the GA code and
> before the</body>  tag.
>
> Any other suggestions?
>
>
>
> Harald Geritzer wrote:
>>
>> hello,
>>
>> i wrote some custom component for one of my projects. it's included just
>> before the closing body tag.
>>
>> <body>
>> ...
>>
>>
>> </body>
>>
>>
>> GoogleTracker.java
>> ==================
>>
>> public class GoogleTracker {
>>
>> @Paramter
>> private String trackerId;
>>
>>
>> public String getTrackerId() {
>> return trackerId;
>> }
>> }
>>
>>
>> GoogleTracker.tml
>> =================
>>
>> <t:container
>> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
>> <script type="text/javascript">
>> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl."
>> : "http://www.");
>> document.write(unescape("%3Cscript src='" + gaJsHost +
>> "google-analytics.com/ga.js'
>> type='text/javascript'%3E%3C/script%3E"));
>> </script>
>> <script type="text/javascript">
>> if (typeof(_gat) == 'object') {
>> var pageTracker = _gat._getTracker("${trackerId}");
>> pageTracker._initData();
>> pageTracker._trackPageview();
>> }
>> </script>
>> </t:container>
>>
>> moritzgilsdorf schrieb:
>>> Hi,
>>>
>>> I have a problem with using Google Analytics in my project. I've added
>>> the
>>> GA scripts in my Layout.tml just before the closing body tag. When
>>> rendering
>>> the Page, Tapestry inserts between the GA scripts and the</body>  the
>>> following code:
>>>
>>> <script type="text/javascript">
>>> <!--
>>> Tapestry.onDOMLoaded(function() {
>>> $('gene').activate();
>>> Tapestry.init({"validate":[["organism",[["required","You must provide a
>>> value for Organism."]]]]});
>>> });
>>> // -->
>>>
>>> I suspect this behavior to cause GA to fail. Does anyone has a similar
>>> problem or knows a quick workaround to solve this?
>>>
>>> Thanks in advance!
>>>
>>> Moritz
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: T5: Include Google Analytics Code

by Thiago H. de Paula Figueiredo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Em Tue, 28 Jul 2009 11:45:10 -0300, Fernando Padilla <fern@...>  
escreveu:

> The google code doesn't HAVE to be the last thing on the page.  It will  
> work anywhere on the page.  You can bring in the js file normally  
> through tapestry's addScriptLink (or IncludeJavascript annotation), and  
> then add the google code through addScript..

As I haven't written a Google Analytics component yet, I just copy and  
paste the HTML snippet GA gave me and it works.

--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: T5: Include Google Analytics Code

by moritzgilsdorf-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


You're right. I found the problem yesterday evening and it is a rather stupid
one.  I just hat a linefeed in the javascript code.

I thought javascript would be more tolerant against such things.

Thanks to all for the suggestions.



Fernando Padilla wrote:

>
> The google code doesn't HAVE to be the last thing on the page.  It will
> work anywhere on the page.  You can bring in the js file normally
> through tapestry's addScriptLink (or IncludeJavascript annotation), and
> then add the google code through addScript..
>
> it would be something like below, but you have to learn how to deal with
> tapestry javascript and renderSupport properly. :)
>
>
>
> renderSupport.addScriptLink("http://www.google-analytics.com/ga.js");
> renderSupport.addScript( "if (typeof(_gat) == 'object') {var pageTracker
> =
> _gat._getTracker("${trackerId}");pageTracker._initData();pageTracker._trackPageview();}"
> );
>
>
>
> On 7/28/09 3:27 AM, moritzgilsdorf wrote:
>> I tried it but it still inserts the tapestry-code after the GA code and
>> before the</body>  tag.
>>
>> Any other suggestions?
>>
>>
>>
>> Harald Geritzer wrote:
>>>
>>> hello,
>>>
>>> i wrote some custom component for one of my projects. it's included just
>>> before the closing body tag.
>>>
>>> <body>
>>> ...
>>>
>>>
>>> </body>
>>>
>>>
>>> GoogleTracker.java
>>> ==================
>>>
>>> public class GoogleTracker {
>>>
>>> @Paramter
>>> private String trackerId;
>>>
>>>
>>> public String getTrackerId() {
>>> return trackerId;
>>> }
>>> }
>>>
>>>
>>> GoogleTracker.tml
>>> =================
>>>
>>> <t:container
>>> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
>>> <script type="text/javascript">
>>> var gaJsHost = (("https:" == document.location.protocol) ?
>>> "https://ssl."
>>> : "http://www.");
>>> document.write(unescape("%3Cscript src='" + gaJsHost +
>>> "google-analytics.com/ga.js'
>>> type='text/javascript'%3E%3C/script%3E"));
>>> </script>
>>> <script type="text/javascript">
>>> if (typeof(_gat) == 'object') {
>>> var pageTracker = _gat._getTracker("${trackerId}");
>>> pageTracker._initData();
>>> pageTracker._trackPageview();
>>> }
>>> </script>
>>> </t:container>
>>>
>>> moritzgilsdorf schrieb:
>>>> Hi,
>>>>
>>>> I have a problem with using Google Analytics in my project. I've added
>>>> the
>>>> GA scripts in my Layout.tml just before the closing body tag. When
>>>> rendering
>>>> the Page, Tapestry inserts between the GA scripts and the</body>  the
>>>> following code:
>>>>
>>>> <script type="text/javascript">
>>>> <!--
>>>> Tapestry.onDOMLoaded(function() {
>>>> $('gene').activate();
>>>> Tapestry.init({"validate":[["organism",[["required","You must provide a
>>>> value for Organism."]]]]});
>>>> });
>>>> // -->
>>>>
>>>> I suspect this behavior to cause GA to fail. Does anyone has a similar
>>>> problem or knows a quick workaround to solve this?
>>>>
>>>> Thanks in advance!
>>>>
>>>> Moritz
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@...
>>> For additional commands, e-mail: users-help@...
>>>
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>
>

--
View this message in context: http://n2.nabble.com/T5%3A-Include-Google-Analytics-Code-tp3200824p3348453.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...