-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a tiny Dynamic component to out google analytics code Signed-off-by: Amedeo Mantica <amedeo.mantica@insigno.it>
- Loading branch information
Amedeo Mantica
committed
Sep 3, 2012
1 parent
59ffdba
commit 9bd5327
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Frameworks/Ajax/ERCoolComponents/Components/CCGoogleAnalytics.api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><wodefinitions> | ||
<wo class="CCGoogleMap.java" wocomponentcontent="false"> | ||
|
||
<binding name="uaid"/> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<validation message="'uaid' is a required binding."> | ||
<unbound name="uaid"/> | ||
</validation> | ||
</wo> | ||
</wodefinitions> |
57 changes: 57 additions & 0 deletions
57
Frameworks/Ajax/ERCoolComponents/Sources/er/coolcomponents/CCGoogleAnalytics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package er.coolcomponents; | ||
|
||
import com.webobjects.appserver.WOAssociation; | ||
import com.webobjects.appserver.WOContext; | ||
import com.webobjects.appserver.WOElement; | ||
import com.webobjects.appserver.WOResponse; | ||
import com.webobjects.foundation.NSDictionary; | ||
|
||
import er.extensions.components.ERXDynamicElement; | ||
|
||
/** | ||
* <p> | ||
* CCGoogle analytics is a very simple compoment (dynamic element) that insert the google analytics code</p> | ||
* <p> | ||
* | ||
* @binding uaid you goocle analytics id: UA-XXXXXX | ||
* | ||
* @author amedeomantica | ||
*/ | ||
|
||
public class CCGoogleAnalytics extends ERXDynamicElement { | ||
|
||
public CCGoogleAnalytics(String name, | ||
NSDictionary<String, WOAssociation> associations, | ||
WOElement children) { | ||
super(name, associations, children); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
|
||
@Override | ||
public void appendToResponse(WOResponse aResponse, WOContext aContext) { | ||
super.appendToResponse(aResponse, aContext); | ||
|
||
String googleId = stringValueForBinding("uaid", aContext.component()); | ||
|
||
if(googleId!=null) { | ||
|
||
aResponse.appendContentString("<script type=\"text/javascript\">"); | ||
|
||
aResponse.appendContentString("var _gaq = _gaq || [];"); | ||
aResponse.appendContentString("_gaq.push(['_setAccount', '" + googleId + "']);"); | ||
aResponse.appendContentString("_gaq.push(['_trackPageview']);"); | ||
aResponse.appendContentString("(function() {"); | ||
aResponse.appendContentString("var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;"); | ||
aResponse.appendContentString("ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';"); | ||
aResponse.appendContentString("var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);"); | ||
aResponse.appendContentString("})();"); | ||
|
||
aResponse.appendContentString("</script>"); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
} |