Skip to content

Commit

Permalink
#15 - Add advanced configuration options for piwik analytics.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruKurz committed Jun 24, 2017
1 parent b34e081 commit 83f3d80
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/rocketchat-analytics/client/loadScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ Template.body.onRendered(() => {
Tracker.autorun((c) => {
const piwikUrl = RocketChat.settings.get('PiwikAnalytics_enabled') && RocketChat.settings.get('PiwikAnalytics_url');
const piwikSiteId = piwikUrl && RocketChat.settings.get('PiwikAnalytics_siteId');
const piwikPrependDomain = piwikUrl && RocketChat.settings.get('PiwikAnalytics_prependDomain');
const piwikCookieDomain = piwikUrl && RocketChat.settings.get('PiwikAnalytics_cookieDomain');
const piwikDomains = piwikUrl && RocketChat.settings.get('PiwikAnalytics_domains');
const googleId = RocketChat.settings.get('GoogleAnalytics_enabled') && RocketChat.settings.get('GoogleAnalytics_ID');
if (piwikSiteId || googleId) {
c.stop();
Expand All @@ -14,6 +17,25 @@ Template.body.onRendered(() => {

window._paq.push(['trackPageView']);
window._paq.push(['enableLinkTracking']);
if (piwikPrependDomain) {
window._paq.push(['setDocumentTitle', `${ window.location.hostname }/${ document.title }`]);
}
const upperLevelDomain = `*.${ window.location.hostname.split('.').slice(1).join('.') }`;
if (piwikCookieDomain) {
window._paq.push(['setCookieDomain', upperLevelDomain]);
}
if (piwikDomains) {
// 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`]);
window._paq.push(['setSiteId', Number.parseInt(piwikSiteId)]);
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-analytics/client/trackEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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;
Expand Down
19 changes: 19 additions & 0 deletions packages/rocketchat-analytics/server/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ RocketChat.settings.addGroup('Analytics', function addSettings() {
i18nLabel: 'Client_ID',
enableQuery
});
this.add('PiwikAnalytics_prependDomain', false, {
type: 'boolean',
public: true,
i18nLabel: 'PiwikAnalytics_prependDomain',
enableQuery
});
this.add('PiwikAnalytics_cookieDomain', false, {
type: 'boolean',
public: true,
i18nLabel: 'PiwikAnalytics_cookieDomain',
enableQuery
});
this.add('PiwikAnalytics_domains', '', {
type: 'string',
multiline: true,
public: true,
i18nLabel: 'PiwikAnalytics_domains',
enableQuery
});
});

this.section('Analytics_Google', function() {
Expand Down
6 changes: 6 additions & 0 deletions packages/rocketchat-i18n/i18n/de.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,12 @@
"Pinned_a_message": "hat eine Nachricht angeheftet:",
"Pinned_Messages": "Fixierte Nachrichten",
"PiwikAnalytics_siteId_Description": "Die Website-ID zur Identifizierung dieser Website. Beispiel: 17",
"PiwikAnalytics_prependDomain" : "Domain voranstellen",
"PiwikAnalytics_prependDomain_Description" : "Domain der Seite beim Tracken dem Seitentitel voranstellen",
"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. 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
6 changes: 6 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,12 @@
"Pinned_a_message": "Pinned a message:",
"Pinned_Messages": "Pinned Messages",
"PiwikAnalytics_siteId_Description": "The site id to use for identifying this site. Example: 17",
"PiwikAnalytics_prependDomain" : "Prepend domain",
"PiwikAnalytics_prependDomain_Description" : "Prepend the site domain to the page title when tracking",
"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. 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 83f3d80

Please sign in to comment.