Skip to content
Permalink
Browse files

[JENKINS-11686] Updated google analytics code to use the asynchronous…

… syntax
  • Loading branch information...
redsolo committed Nov 22, 2011
1 parent 3d657d1 commit f6e67c5fe06a923af2eb6e6728044d9a62b0e149

This file was deleted.

@@ -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>

@@ -1,3 +1,5 @@
<div>
You can track subdomains within the same profile as the domain.
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 was deleted.

@@ -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());
}
}
@@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<hudson.plugins.google.analytics.GoogleAnalyticsPageDecorator>
<profileId>AProfileId</profileId>
</hudson.plugins.google.analytics.GoogleAnalyticsPageDecorator>
@@ -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>
@@ -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>
@@ -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>

0 comments on commit f6e67c5

Please sign in to comment.
You can’t perform that action at this time.