Skip to content

Commit

Permalink
Add settings for Piwik Analytics, for #233
Browse files Browse the repository at this point in the history
Right now this is a very basic implementation and only tracks the first page view. Later implementations might extend this further.

Couldn't exactly test locally for some reason, so I am committing this to test via the requested deployment.
  • Loading branch information
graywolf336 committed May 19, 2016
1 parent 3674735 commit a2c5754
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion 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 Expand Up @@ -1175,4 +1181,4 @@
"Your_mail_was_sent_to_s" : "Your mail was sent to %s",
"Your_password_is_wrong" : "Your password is wrong!",
"Your_push_was_sent_to_s_devices" : "Your push was sent to %s devices"
}
}
3 changes: 3 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,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, i18nDescription: 'PiwikAnalytics_url_Description' }
@add 'PiwikAnalytics_siteId', '', { type: 'string', public: false, i18nDescription: 'PiwikAnalytics_siteId_Description' }
@add 'PiwikAnalytics_domains', '', { type: 'string', public: false, i18nDescription: 'PiwikAnalytics_domains_Description' }
@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

0 comments on commit a2c5754

Please sign in to comment.