Skip to content

Commit

Permalink
Merge pull request #18 from mrsimpson/feature/15-piwik-analytics
Browse files Browse the repository at this point in the history
#15 - Add advanced configuration options for piwik analytics.
  • Loading branch information
mrsimpson authored Jun 14, 2017
2 parents e120102 + 0202962 commit b85982a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
18 changes: 13 additions & 5 deletions packages/rocketchat-analytics/client/loadScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ Template.body.onRendered(() => {
window._paq.push(['trackPageView']);
window._paq.push(['enableLinkTracking']);
if (piwikPrependDomain) {
window._paq.push(['setDocumentTitle', document.domain + '/' + document.title]);
window._paq.push(['setDocumentTitle', `${ window.location.hostname }/${ document.title }`]);
}
var parts = document.domain.split('.');parts.shift();
var subDomains = `*.${ parts.join('.') }`;
const upperLevelDomain = `*.${ window.location.hostname.split('.').slice(1).join('.') }`;
if (piwikCookieDomain) {
window._paq.push(['setCookieDomain', subDomains]);
window._paq.push(['setCookieDomain', upperLevelDomain]);
}
if (piwikDomains) {
window._paq.push(['setDomains', [subDomains]]);
// array
const domainsArray = piwikDomains.split(/\n/);
let domains = [];
for (let i = 0; i < domainsArray.length; i++) {
// only push domain if it contains a non whitespace character.
if (/\S/.test(domainsArray[i])) {
domains.push(`*.${ domainsArray[i].trim() }`);
}
}
window._paq.push(['setDomains', domains]);
}
(() => {
window._paq.push(['setTrackerUrl', `${ piwikUrl }piwik.php`]);
Expand Down
9 changes: 2 additions & 7 deletions packages/rocketchat-analytics/client/trackEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ function trackEvent(category, action, label) {
}

if (!window._paq || window.ga) {
//Trigger the trackPageView manually as the page views don't seem to be tracked
//Trigger the trackPageView manually as the page views are only loaded when the loadScript.js code is executed
FlowRouter.triggers.enter([(route) => {
if (window._paq) {
const http = location.protocol;
const slashes = http.concat('//');
let host = slashes.concat(window.location.hostname);
if (RocketChat.settings.get('PiwikAnalytics_cookieDomain')) {
let parts = window.location.hostname.split('.');parts.shift();
let subDomains = parts.join('.');
host = slashes.concat(subDomains);
}
const host = slashes.concat(window.location.hostname);
window._paq.push(['setCustomUrl', host + route.path]);
window._paq.push(['trackPageView']);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/rocketchat-analytics/server/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ RocketChat.settings.addGroup('Analytics', function addSettings() {
i18nLabel: 'PiwikAnalytics_cookieDomain',
enableQuery
});
this.add('PiwikAnalytics_domains', false, {
type: 'boolean',
this.add('PiwikAnalytics_domains', '', {
type: 'string',
multiline: true,
public: true,
i18nLabel: 'PiwikAnalytics_domains',
enableQuery
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-i18n/i18n/de.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@
"PiwikAnalytics_cookieDomain" : "Alle Subdomains",
"PiwikAnalytics_cookieDomain_Description" : "Besucher aufzeichnen auf allen Subdomains",
"PiwikAnalytics_domains" : "Verberge ausgehende Links",
"PiwikAnalytics_domains_Description" : "Verberge im Bericht über 'ausgehende Verweise' alle Klicks auf bekannte Alias-URLs",
"PiwikAnalytics_domains_Description" : "Verberge im Bericht über 'ausgehende Verweise' alle Klicks auf bekannte Alias-URLs. Bitte tragen Sie pro Zeile einen Domainnamen ein, verwenden Sie dabei keine Trennzeichen.",
"PiwikAnalytics_url_Description": "Die Piwik URL benötigt ein trailing slash. Beispiel: //piwik.rocket.chat/",
"Placeholder_for_email_or_username_login_field": "Platzhalter für das Feld der E-Mail-Adresse und des Benutzernamen",
"Placeholder_for_password_login_field": "Platzhalter für das Feld des Anmeldepassworts",
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@
"PiwikAnalytics_cookieDomain" : "All subdomains",
"PiwikAnalytics_cookieDomain_Description" : "Track visitors across all subdomains",
"PiwikAnalytics_domains" : "Hide outgoing links",
"PiwikAnalytics_domains_Description" : "In the 'Outlinks' report, hide clicks to known alias URLs",
"PiwikAnalytics_domains_Description" : "In the 'Outlinks' report, hide clicks to known alias URLs. Please insert one domain per line and do not use any separators.",
"PiwikAnalytics_url_Description": "The url where the Piwik resides, be sure to include the trailing slash. Example: //piwik.rocket.chat/",
"Placeholder_for_email_or_username_login_field": "Placeholder for email or username login field",
"Placeholder_for_password_login_field": "Placeholder for password login field",
Expand Down

0 comments on commit b85982a

Please sign in to comment.