Skip to content

Commit bc801b0

Browse files
authored
Merge pull request jenkinsci#3 from ilja-radusch/fix-senduserid-bug-and-configure-scripts
2 parents fd97851 + c94e5ae commit bc801b0

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

src/main/java/io/jenkins/plugins/matomoanalytics/MatomoPageDecorator.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class MatomoPageDecorator extends PageDecorator {
1313
private String matomoSiteID;
1414
private String matomoServer;
1515
private String matomoPath;
16+
private String matomoPhp;
17+
private String matomoJs;
1618
private boolean matomoUseHttps = true;
1719
private boolean matomoSendUserID = false;
1820

@@ -25,12 +27,16 @@ public MatomoPageDecorator() {
2527
public MatomoPageDecorator(String matomoSiteID,
2628
String matomoServer,
2729
String matomoPath,
30+
String matomoPhp,
31+
String matomoJs,
2832
boolean matomoUseHttps,
2933
boolean matomoSendUserID) {
3034
this();
3135
setMatomoSiteID(matomoSiteID);
3236
setMatomoServer(matomoServer);
3337
setMatomoPath(matomoPath);
38+
setMatomoPhp(matomoPhp);
39+
setMatomoJs(matomoJs);
3440
setMatomoUseHttps(matomoUseHttps);
3541
setMatomoSendUserID(matomoSendUserID);
3642
}
@@ -67,6 +73,22 @@ public void setMatomoPath(String matomoPath) {
6773
this.matomoPath = matomoPath;
6874
}
6975

76+
public String getMatomoPhp() {
77+
return matomoPhp;
78+
}
79+
80+
public void setMatomoPhp(String matomoPhp) {
81+
this.matomoPhp = matomoPhp;
82+
}
83+
84+
public String getMatomoJs() {
85+
return matomoJs;
86+
}
87+
88+
public void setMatomoJs(String matomoJs) {
89+
this.matomoJs = matomoJs;
90+
}
91+
7092
public boolean isMatomoUseHttps() {
7193
return matomoUseHttps;
7294
}

src/main/resources/io/jenkins/plugins/matomoanalytics/MatomoPageDecorator/footer.jelly

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,34 @@
55
<!-- Matomo -->
66
<script>
77
var _paq = window._paq = window._paq || [];
8+
_paq.push(["setDomains", [
9+
<j:forEach var="d" items="${instance.domains}">
10+
"${d}"<j:if test="${!d_last}">,</j:if>
11+
</j:forEach>
12+
] ]);
813
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
914
_paq.push(['trackPageView']);
1015
_paq.push(['enableLinkTracking']);
1116
var d = document;
12-
if ("${it.matomoSendUserID}") {
13-
var userID, userIDNode, Nodes = d.getElementsByClassName('hidden-xs hidden-sm');
14-
if (Nodes !== undefined) {
15-
_paq.push(['setUserId', Nodes[0].textContent]);
16-
}
17+
if (${it.matomoSendUserID}) {
18+
_paq.push(['setUserId', "${app.authentication.name}".trim()]);
19+
} else {
20+
_paq.push(["setDoNotTrack", true]);
1721
}
1822
(function () {
1923
var u = "${it.protocolString}${it.matomoServer}${it.matomoPath}";
20-
_paq.push(['setTrackerUrl', u + 'matomo.php']);
24+
var matomoPhp = "${it.matomoPhp ?: 'matomo.php'}";
25+
var matomoJs = "${it.matomoJs ?: 'matomo.js'}";
26+
27+
_paq.push(['setTrackerUrl', u + matomoPhp]);
2128
_paq.push(['setSiteId', ${it.matomoSiteID}]);
2229
var g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
2330
g.async = true;
24-
g.src = u + 'matomo.js';
31+
g.src = u + matomoJs;
2532
s.parentNode.insertBefore(g, s);
2633
})();
2734
</script>
2835
<!-- End Matomo Code -->
2936
</j:when>
3037
</j:choose>
31-
</j:jelly>
38+
</j:jelly>

src/main/resources/io/jenkins/plugins/matomoanalytics/MatomoPageDecorator/global.jelly

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,14 @@
1616
<f:entry title="${%Use https}" field="matomoUseHttps" help="/plugin/matomo-analytics/matomousehttps.html">
1717
<f:checkbox/>
1818
</f:entry>
19+
<!-- Advanced section for PHP & JS -->
20+
<f:advanced>
21+
<f:entry title="${%Matomo PHP file}" help="/plugin/matomo-analytics/matomophp.html">
22+
<f:textbox field="matomoPhp" default="matomo.php"/>
23+
</f:entry>
24+
<f:entry title="${%Matomo JS file}" help="/plugin/matomo-analytics/matomojs.html">
25+
<f:textbox field="matomoJs" default="matomo.js"/>
26+
</f:entry>
27+
</f:advanced>
1928
</f:section>
20-
</j:jelly>
29+
</j:jelly>

src/main/webapp/matomojs.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
The JavaScript file of the Matomo instance. Example: matomo.js
3+
</div>

src/main/webapp/matomophp.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
The PHP file of the Matomo instance. Example: matomo.php
3+
</div>

0 commit comments

Comments
 (0)