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

Add settings for Piwik Analytics, for #233 #3299

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 6 additions & 0 deletions packages/rocketchat-lib/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,12 @@
"Pin_Message" : "Pin Message",
"Pinned_a_message" : "Pinned a message:",
"Pinned_Messages" : "Pinned Messages",
"PiwikAnalytics_url" : "Piwik Url",
"PiwikAnalytics_url_Description" : "The url where the Piwik resides, be sure to include the trialing slash. Example: //piwik.rocket.chat/",
"PiwikAnalytics_siteId" : "Piwik Site ID",
"PiwikAnalytics_siteId_Description" : "The site id to use for identifying this site. Example: 17",
"PiwikAnalytics_domains" : "Piwiki Domains",
"PiwikAnalytics_domains_Description" : "The domains which to track, separated by spaces. Example: *.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",
"Please_add_a_comment" : "Please add a comment",
Expand Down
5 changes: 5 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
if not RocketChat.models.Settings.findOneById 'uniqueID'
RocketChat.models.Settings.createWithIdAndValue 'uniqueID', process.env.DEPLOYMENT_ID or Random.id()

# When you define a setting and want to add a description, you don't need to automatically define the i18nDescription
# if you add a node to the i18n.json with the same setting name but with `_Description` it will automatically work.
RocketChat.settings.addGroup 'Accounts', ->
@add 'Accounts_AllowDeleteOwnAccount', false, { type: 'boolean', public: true, enableQuery: { _id: 'Accounts_AllowUserProfileChange', value: true } }
@add 'Accounts_AllowUserProfileChange', true, { type: 'boolean', public: true }
Expand Down Expand Up @@ -92,6 +94,9 @@ RocketChat.settings.addGroup 'General', ->
@add 'Force_SSL', false, { type: 'boolean', public: true }
@add 'GoogleTagManager_id', '', { type: 'string', public: true }
@add 'GoogleSiteVerification_id', '', { type: 'string', public: false }
@add 'PiwikAnalytics_url', '', { type: 'string', public: false }
@add 'PiwikAnalytics_siteId', '', { type: 'string', public: false }
@add 'PiwikAnalytics_domains', '', { type: 'string', public: false }
@add 'Restart', 'restart_server', { type: 'action', actionText: 'Restart_the_server' }

@section 'UTF8', ->
Expand Down
24 changes: 24 additions & 0 deletions packages/rocketchat-ui-master/master/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ Template.body.onRendered ->
j.src = '//www.googletagmanager.com/gtm.js?id=' + i + dl
f.parentNode.insertBefore j, f

Tracker.autorun (c) ->
w = window
p = '_paq'
url = RocketChat.settings.get 'PiwikAnalytics_url'
siteId = RocketChat.settings.get 'PiwikAnalytics_siteId'
domains = RocketChat.settings.get 'PiwikAnalytics_domains'
if Match.test(url, String) and url.trim() isnt '' and Match.test(siteId, String) and siteId.trim() isnt '' and Match.test(domains, String) and domains.trim() isnt ''
c.stop()
do (w, p, url, siteId, domains) ->
w[p] = w[p] || []
w[p].push(['setDomains', [domains.split(' ')]])
w[p].push(['trackPageView'])
w[p].push(['enableLinkTracking'])
w[p].push(['setTrackerUrl', url + 'piwik.php'])
w[p].push(['setSiteId', Number.parseInt(siteId)])
d = document
g = d.createElement('script')
s = d.getElementsByTagName('script')[0]
g.type = 'text/javascript'
g.async = true
g.defer = true
g.src = url + 'piwik.js'
s.parentNode.insertBefore(g, s)

Tracker.autorun (c) ->
if RocketChat.settings.get 'Meta_language'
c.stop()
Expand Down