Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Adding support for piwik sub domain settings #7324

Merged
merged 3 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/rocketchat-analytics/client/loadScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ 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 piwikAdditionalTracker = piwikUrl && RocketChat.settings.get('PiwikAdditionalTrackers');
const googleId = RocketChat.settings.get('GoogleAnalytics_enabled') && RocketChat.settings.get('GoogleAnalytics_ID');
if (piwikSiteId || googleId) {
c.stop();
Expand All @@ -14,7 +18,31 @@ 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/);
const 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]);
}
(() => {
const addTrackers = JSON.parse(piwikAdditionalTracker);
for (let i = 0; i < addTrackers.length; i++) {
const tracker = addTrackers[i];
window._paq.push(['addTracker', `${ tracker['trackerURL'] }piwik.php`, tracker['siteId']]);
}
window._paq.push(['setTrackerUrl', `${ piwikUrl }piwik.php`]);
window._paq.push(['setSiteId', Number.parseInt(piwikSiteId)]);
const d = document;
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
26 changes: 26 additions & 0 deletions packages/rocketchat-analytics/server/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@ RocketChat.settings.addGroup('Analytics', function addSettings() {
i18nLabel: 'Client_ID',
enableQuery
});
this.add('PiwikAdditionalTrackers', '', {
type: 'string',
multiline: true,
public: true,
i18nLabel: 'PiwikAdditionalTrackers',
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
8 changes: 8 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,14 @@
"Pinned_a_message": "hat eine Nachricht angeheftet:",
"Pinned_Messages": "Fixierte Nachrichten",
"PiwikAnalytics_siteId_Description": "Die Website-ID zur Identifizierung dieser Website. Beispiel: 17",
"PiwikAdditionalTrackers" : "Zusätzliche Piwik Websites",
"PiwikAdditionalTrackers_Description" : "Geben Sie hier weitere Piwik Website URLs und SiteIDs in folgendem Format an, wenn Sie dieselben Daten in verschiedene Piwik Instanzen tracken möchten: [ { \"trackerURL\" : \"https://my.piwik.domain2/\", \"siteId\" : 42 }, { \"trackerURL\" : \"https://my.piwik.domain3/\", \"siteId\" : 15 } ]",
"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
8 changes: 8 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,14 @@
"Pinned_a_message": "Pinned a message:",
"Pinned_Messages": "Pinned Messages",
"PiwikAnalytics_siteId_Description": "The site id to use for identifying this site. Example: 17",
"PiwikAdditionalTrackers" : "Additional piwik sites",
"PiwikAdditionalTrackers_Description" : "Enter addtitional Piwik website URLs and SiteIDs in the following format, if you wnat to track the same data into different websites: [ { \"trackerURL\" : \"https://my.piwik.domain2/\", \"siteId\" : 42 }, { \"trackerURL\" : \"https://my.piwik.domain3/\", \"siteId\" : 15 } ]",
"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