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 11, 2017
1 parent 95e7d6c commit 9c77df4
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 88 deletions.
15 changes: 15 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 googleId = RocketChat.settings.get('GoogleAnalytics_enabled') && RocketChat.settings.get('GoogleAnalytics_ID');
if (piwikSiteId || googleId) {
c.stop();
Expand All @@ -14,6 +18,17 @@ Template.body.onRendered(() => {

window._paq.push(['trackPageView']);
window._paq.push(['enableLinkTracking']);
if (piwikPrependDomain) {
window._paq.push(['setDocumentTitle', document.domain + '/' + document.title]);
}
var parts = document.domain.split('.');parts.shift();
var subDomains = `*.${ parts.join('.') }`;
if (piwikCookieDomain) {
window._paq.push(['setCookieDomain', subDomains]);
}
if (piwikDomains) {
window._paq.push(['setDomains', [subDomains]]);
}
(() => {
window._paq.push(['setTrackerUrl', `${ piwikUrl }piwik.php`]);
window._paq.push(['setSiteId', Number.parseInt(piwikSiteId)]);
Expand Down
19 changes: 18 additions & 1 deletion packages/rocketchat-analytics/server/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +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', false, {
type: 'boolean',
public: true,
i18nLabel: 'PiwikAnalytics_domains',
enableQuery
});
});

this.section('Analytics_Google', function() {
const enableQuery = {_id: 'GoogleAnalytics_enabled', value: true};
this.add('GoogleAnalytics_enabled', false, {
Expand Down
Loading

0 comments on commit 9c77df4

Please sign in to comment.