Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JENKINS-11686] Updated google analytics code to use the asynchronous…
… syntax
- Loading branch information
Showing
with
180 additions
and 79 deletions.
- +0 −16 src/main/resources/hudson/plugins/google/analytics/GoogleAnalyticsPageDecorator/footer.jelly
- +27 −0 src/main/resources/hudson/plugins/google/analytics/GoogleAnalyticsPageDecorator/header.jelly
- +3 −1 src/main/webapp/domainName.html
- +0 −62 src/test/java/hudson/plugins/google/analytics/FooterWebTest.java
- +91 −0 src/test/java/hudson/plugins/google/analytics/HeaderWebTest.java
- 0 ...hudson/plugins/google/analytics/{FooterWebTest → HeaderWebTest}/GoogleAnalyticsChild/footer.jelly
- 0 ...testFooterContainsProfileWithDomainName → HeaderWebTest/testHeadElementContainsScript}/config.xml
- 0 ...t/testHeadElementContainsScript}/hudson.plugins.google.analytics.GoogleAnalyticsPageDecorator.xml
- 0 ...ntainsProfileWithinQuotation → HeaderWebTest/testScriptContainsProfileWithinQuotation}/config.xml
- +4 −0 ...ptContainsProfileWithinQuotation/hudson.plugins.google.analytics.GoogleAnalyticsPageDecorator.xml
- +25 −0 src/test/resources/hudson/plugins/google/analytics/HeaderWebTest/testScriptForDomain/config.xml
- 0 ...aderWebTest/testScriptForDomain}/hudson.plugins.google.analytics.GoogleAnalyticsPageDecorator.xml
- +25 −0 ...ces/hudson/plugins/google/analytics/HeaderWebTest/testScriptForMultipleTopLevelDomains/config.xml
- +5 −0 ...ScriptForMultipleTopLevelDomains/hudson.plugins.google.analytics.GoogleAnalyticsPageDecorator.xml
There are no files selected for viewing
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
@@ -0,0 +1,27 @@ | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
<j:if test="${it.profileId!=null}"> | ||
<script type="text/javascript"> | ||
var _gaq = _gaq || []; | ||
_gaq.push(['_setAccount', '${it.profileId}']); | ||
<j:if test="${it.domainName!=null}"> | ||
<j:choose> | ||
<j:when test="${it.domainName=='none'}"> | ||
_gaq.push(['_setDomainName', 'none']); | ||
_gaq.push(['_setAllowLinker', true]); | ||
</j:when> | ||
<j:otherwise> | ||
_gaq.push(['_setDomainName', '${it.domainName}']); | ||
</j:otherwise> | ||
</j:choose> | ||
</j:if> | ||
_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); | ||
})(); | ||
</script> | ||
</j:if> | ||
</j:jelly> | ||
|
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
@@ -1,3 +1,5 @@ | ||
<div> | ||
You can track subdomains within the same profile as the domain.<br/> | ||
<br/> | ||
If you want to track traffic where Jenkins is limited to a sub-directory of a domain, use <i>none</i>. For more information see <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#domainAndSubDirectory">Tracking Between a Domain and a Sub-Directory on Another Domain</a> | ||
</div> |
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
@@ -0,0 +1,91 @@ | ||
package hudson.plugins.google.analytics; | ||
|
||
import hudson.model.PageDecorator; | ||
import org.jvnet.hudson.test.HudsonTestCase; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
import com.gargoylesoftware.htmlunit.WebAssert; | ||
import com.gargoylesoftware.htmlunit.html.HtmlButton; | ||
import com.gargoylesoftware.htmlunit.html.HtmlForm; | ||
import com.gargoylesoftware.htmlunit.html.HtmlHead; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
|
||
public class HeaderWebTest extends HudsonTestCase { | ||
|
||
/** | ||
* Asserts that the analytics script is in the head element. | ||
*/ | ||
@LocalData | ||
public void testHeadElementContainsScript() throws Exception { | ||
WebClient webClient = new WebClient(); | ||
webClient.setJavaScriptEnabled(false); | ||
HtmlPage page = webClient.goTo("configure"); | ||
WebAssert.assertInputContainsValue(page, "_.profileId", "AProfileId"); | ||
HtmlHead item = (HtmlHead) page.getElementsByTagName(HtmlHead.TAG_NAME).item(0); | ||
assertTrue("The page text did not contain the google analytics script", | ||
item.asXml().contains("_gaq.push(['_setAccount', 'AProfileId']);")); | ||
} | ||
|
||
/** | ||
* Asserts that the header contains the profile within quotes. | ||
*/ | ||
@LocalData | ||
public void testScriptContainsProfileWithinQuotation() throws Exception { | ||
WebClient webClient = new WebClient(); | ||
webClient.setJavaScriptEnabled(false); | ||
HtmlPage page = webClient.goTo("configure"); | ||
WebAssert.assertInputContainsValue(page, "_.profileId", "AProfileId"); | ||
assertTrue("The page text did not contain the profile", | ||
page.asXml().contains("_gaq.push(['_setAccount', 'AProfileId']);")); | ||
} | ||
/** | ||
* Asserts that page contains the profile within quotes. | ||
*/ | ||
@LocalData | ||
public void testScriptForDomain() throws Exception { | ||
WebClient webClient = new WebClient(); | ||
webClient.setJavaScriptEnabled(false); | ||
HtmlPage page = webClient.goTo("configure"); | ||
WebAssert.assertInputContainsValue(page, "_.domainName", "ADomain"); | ||
assertTrue("The page text did not contain the _setDomainName value", | ||
page.asXml().contains("_gaq.push(['_setDomainName', 'ADomain']);")); | ||
} | ||
/** | ||
* Asserts that page contains the profile within quotes. | ||
*/ | ||
@LocalData | ||
public void testScriptForMultipleTopLevelDomains() throws Exception { | ||
WebClient webClient = new WebClient(); | ||
webClient.setJavaScriptEnabled(false); | ||
HtmlPage page = webClient.goTo("configure"); | ||
WebAssert.assertInputContainsValue(page, "_.domainName", "none"); | ||
assertTrue("The page text did not contain the none Domain name", | ||
page.asXml().contains("_gaq.push(['_setDomainName', 'none']);")); | ||
assertTrue("The page text did not contain the _setAllowLinker value", | ||
page.asXml().contains("_gaq.push(['_setAllowLinker', true]);")); | ||
} | ||
/** | ||
* Asserts that the header does not contain the google analytics script. | ||
*/ | ||
public void testEmptyHeaderIfEmptyProfileId() throws Exception { | ||
WebClient webClient = new WebClient(); | ||
webClient.setJavaScriptEnabled(false); | ||
HtmlPage page = webClient.goTo("configure"); | ||
WebAssert.assertInputContainsValue(page, "_.profileId", ""); | ||
assertFalse("The page text contained the profile", | ||
page.asXml().contains("_gaq.push(['_setAccount', 'AProfileId']);")); | ||
} | ||
|
||
/** | ||
* Asserts that the profile id for decorator is updated when submitted | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
public void testSubmittingConfigurationUpdatesProfileId() throws Exception { | ||
WebClient webClient = new WebClient(); | ||
webClient.setThrowExceptionOnScriptError(false); | ||
HtmlForm form = webClient.goTo("configure").getFormByName("config"); | ||
form.getInputByName("_.profileId").setValueAttribute("NewProfile"); | ||
form.submit((HtmlButton)last(form.getHtmlElementsByTagName("button"))); | ||
assertEquals("The new profile id wasnt correct", "NewProfile", ((GoogleAnalyticsPageDecorator) PageDecorator.all().get(0)).getProfileId()); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
@@ -0,0 +1,4 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson.plugins.google.analytics.GoogleAnalyticsPageDecorator> | ||
<profileId>AProfileId</profileId> | ||
</hudson.plugins.google.analytics.GoogleAnalyticsPageDecorator> |
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
@@ -0,0 +1,25 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<version>1.318</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/> | ||
<securityRealm class="hudson.security.SecurityRealm$None"/> | ||
<jdks/> | ||
<clouds/> | ||
<slaves/> | ||
<quietPeriod>5</quietPeriod> | ||
<scmCheckoutRetryCount>0</scmCheckoutRetryCount> | ||
<views> | ||
<hudson.model.AllView> | ||
<owner class="hudson" reference="../../.."/> | ||
<name>All</name> | ||
</hudson.model.AllView> | ||
</views> | ||
<primaryView>All</primaryView> | ||
<slaveAgentPort>0</slaveAgentPort> | ||
<label></label> | ||
<nodeProperties/> | ||
<globalNodeProperties/> | ||
<disabledAdministrativeMonitors/> | ||
</hudson> |
File renamed without changes.
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
@@ -0,0 +1,25 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<version>1.318</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/> | ||
<securityRealm class="hudson.security.SecurityRealm$None"/> | ||
<jdks/> | ||
<clouds/> | ||
<slaves/> | ||
<quietPeriod>5</quietPeriod> | ||
<scmCheckoutRetryCount>0</scmCheckoutRetryCount> | ||
<views> | ||
<hudson.model.AllView> | ||
<owner class="hudson" reference="../../.."/> | ||
<name>All</name> | ||
</hudson.model.AllView> | ||
</views> | ||
<primaryView>All</primaryView> | ||
<slaveAgentPort>0</slaveAgentPort> | ||
<label></label> | ||
<nodeProperties/> | ||
<globalNodeProperties/> | ||
<disabledAdministrativeMonitors/> | ||
</hudson> |
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
@@ -0,0 +1,5 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson.plugins.google.analytics.GoogleAnalyticsPageDecorator> | ||
<profileId>AProfileId</profileId> | ||
<domainName>none</domainName> | ||
</hudson.plugins.google.analytics.GoogleAnalyticsPageDecorator> |