Skip to content

Commit 7f07305

Browse files
committed
Add self tracking capabilities
1 parent 067f92e commit 7f07305

File tree

4 files changed

+171
-127
lines changed

4 files changed

+171
-127
lines changed

frontend/express/app.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ plugins.setConfigs("frontend", {
116116
session_timeout: 30,
117117
use_google: true,
118118
code: true,
119-
google_maps_api_key: "",
120119
offline_mode: false,
120+
self_tracking: "",
121121
});
122122

123123
if (!plugins.isPluginEnabled('tracker')) {
@@ -137,7 +137,6 @@ plugins.setUserConfigs("frontend", {
137137
session_timeout: false,
138138
use_google: false,
139139
code: false,
140-
google_maps_api_key: ""
141140
});
142141

143142
plugins.setConfigs("security", {

frontend/express/views/dashboard.html

+156-124
Original file line numberDiff line numberDiff line change
@@ -1886,148 +1886,180 @@ <h4><a href="#/analytics/events/key/{{encodeURIComponent this.name}}">{{this.nam
18861886

18871887
<script>Backbone.history.start();</script>
18881888
<% if (!offline_mode) { %>
1889-
<% if (!track || track == "GA" && member['global_admin'] || track == "noneGA" && !member['global_admin']) { %>
1890-
<!--Countly script-->
1891-
<script type='text/javascript' src='<%- cdn %>sdk/web/countly.min.js?<%= countlyVersion %>'></script>
1892-
<script type='text/javascript'>
1893-
1894-
Countly.getViewName = function(){
1895-
var view = "/dashboard#";
1896-
var fragment = Backbone.history.getFragment();
1897-
var parts = fragment.split("/");
1898-
if (fragment.indexOf("/analytics/retention/") === 0) {
1899-
parts[4] = ":event";
1900-
}
1901-
if (fragment.indexOf("/attribution/") === 0) {
1902-
parts[2] = ":campaign_id";
1903-
}
1904-
for (var i = 1; i < parts.length; i++) {
1905-
if (/\d/.test(parts[i])) {
1906-
parts[i] = ":id";
1907-
}
1908-
if (parts[i][0] === "{") {
1909-
parts[i] = ":query";
1910-
}
1889+
<!--Countly script-->
1890+
<script type='text/javascript' src='<%- cdn %>sdk/web/countly.min.js?<%= countlyVersion %>'></script>
1891+
<script type='text/javascript'>
1892+
1893+
Countly.getViewName = function(){
1894+
var view = "/dashboard#";
1895+
var fragment = Backbone.history.getFragment();
1896+
var parts = fragment.split("/").slice(0, 3);
1897+
if (fragment.indexOf("/attribution/") === 0) {
1898+
parts[2] = ":campaign_id";
1899+
}
1900+
if (fragment.indexOf("/users/") === 0 && parts.length === 3) {
1901+
parts[2] = ":user_id";
1902+
}
1903+
for (var i = 1; i < parts.length; i++) {
1904+
if (/\d/.test(parts[i])) {
1905+
parts[i] = ":id";
19111906
}
1912-
return view + parts.join("/");
1913-
};
1914-
1915-
Countly.getViewUrl = function(){
1916-
var view = "/dashboard#";
1917-
var fragment = Backbone.history.getFragment();
1918-
var parts = fragment.split("/");
1919-
if (fragment.indexOf("/analytics/retention/") === 0) {
1920-
parts[4] = "[CLY]_session";
1907+
if (parts[i][0] === "{") {
1908+
parts[i] = ":query";
19211909
}
1922-
if (fragment.indexOf("/attribution/") === 0) {
1923-
parts[2] = "";
1910+
}
1911+
return view + parts.join("/");
1912+
};
1913+
1914+
Countly.getViewUrl = function(){
1915+
var view = "/dashboard#";
1916+
var fragment = Backbone.history.getFragment();
1917+
var parts = fragment.split("/").slice(0, 3);
1918+
if (fragment.indexOf("/attribution/") === 0) {
1919+
parts[2] = "";
1920+
}
1921+
if (fragment.indexOf("/users/") === 0 && parts.length === 3) {
1922+
parts[2] = "";
1923+
}
1924+
for (var i = 1; i < parts.length; i++) {
1925+
if (/\d/.test(parts[i])) {
1926+
parts[i] = "";
19241927
}
1925-
for (var i = 1; i < parts.length; i++) {
1926-
if (/\d/.test(parts[i])) {
1927-
parts[i] = "";
1928-
}
1929-
if (parts[i][0] === "{") {
1930-
parts[i] = "{}";
1931-
}
1928+
if (parts[i][0] === "{") {
1929+
parts[i] = "{}";
19321930
}
1933-
return view + parts.join("/");
1934-
};
1931+
}
1932+
return view + parts.join("/");
1933+
};
19351934

1936-
if (countlyGlobal.countly_tracking) {
1937-
var domain = countlyGlobal.countly_domain;
1935+
if (countlyGlobal.countly_tracking) {
1936+
var domain = countlyGlobal.countly_domain;
19381937

1939-
try {
1940-
// try to extract hostname from full domain url
1941-
var urlObj = new URL(domain);
1942-
domain = urlObj.hostname;
1943-
}
1944-
catch (_) {
1945-
// do nothing, domain from config will be used as is
1946-
}
1938+
try {
1939+
// try to extract hostname from full domain url
1940+
var urlObj = new URL(domain);
1941+
domain = urlObj.hostname;
1942+
}
1943+
catch (_) {
1944+
// do nothing, domain from config will be used as is
1945+
}
19471946

1948-
//initializing countly with params
1949-
Countly.init({
1950-
app_key: countlyGlobal.frontend_app,
1951-
url: countlyGlobal.frontend_server,
1952-
device_id: domain,
1953-
app_version: "<%= countlyVersion %>",
1954-
interval:1000
1955-
});
1947+
//initializing countly with params
1948+
Countly.init({
1949+
app_key: countlyGlobal.frontend_app,
1950+
url: countlyGlobal.frontend_server,
1951+
device_id: domain,
1952+
app_version: "<%= countlyVersion %>",
1953+
interval:1000
1954+
});
19561955

1957-
// if domain has changed since the last time it is saved as device id set the new domain as device id and merge it with the old domain
1958-
if (Countly.get_device_id() !== domain) {
1959-
Countly.change_id(domain, true);
1960-
}
1956+
// if domain has changed since the last time it is saved as device id set the new domain as device id and merge it with the old domain
1957+
if (Countly.get_device_id() !== domain) {
1958+
Countly.change_id(domain, true);
1959+
}
1960+
1961+
//track sessions automatically
1962+
Countly.track_sessions();
19611963

1962-
//track sessions automatically
1963-
Countly.track_sessions();
1964+
//track pageviews automatically
1965+
Countly.track_pageview(Countly.getViewName());
19641966

1965-
//track pageviews automatically
1967+
$(window).on('hashchange', function() {
19661968
Countly.track_pageview(Countly.getViewName());
1969+
});
1970+
1971+
//track any clicks to webpages automatically
1972+
Countly.track_clicks();
19671973

1968-
$(window).on('hashchange', function() {
1969-
Countly.track_pageview(Countly.getViewName());
1974+
//track javascript errors
1975+
Countly.track_errors();
1976+
1977+
//display in app messages
1978+
if (Countly.content.enterContentZone) {
1979+
Countly.content.enterContentZone();
1980+
}
1981+
1982+
if (Countly.report_trace && window.performance && window.performance.timing) {
1983+
$(window).on( "load", function(){
1984+
setTimeout(function(){
1985+
var trace = {
1986+
type: "device",
1987+
name: Countly.getViewName(),
1988+
stz: window.performance.timing.navigationStart,
1989+
etz: window.performance.timing.domContentLoadedEventEnd,
1990+
apm_metrics: {}
1991+
};
1992+
if (window.performance.timing.domLoading && window.performance.timing.navigationStart) {
1993+
trace.apm_metrics.first_paint = window.performance.timing.domLoading - window.performance.timing.navigationStart;
1994+
}
1995+
if (window.performance.timing.domContentLoadedEventStart && window.performance.timing.navigationStart) {
1996+
trace.apm_metrics.first_contentful_paint = window.performance.timing.domContentLoadedEventStart - window.performance.timing.navigationStart;
1997+
}
1998+
if (window.performance.timing.domInteractive && window.performance.timing.navigationStart) {
1999+
trace.apm_metrics.dom_interactive = window.performance.timing.domInteractive - window.performance.timing.navigationStart;
2000+
}
2001+
if (window.performance.timing.domContentLoadedEventEnd && window.performance.timing.domContentLoadedEventStart) {
2002+
trace.apm_metrics.dom_content_loaded_event_end = window.performance.timing.domContentLoadedEventEnd - window.performance.timing.domContentLoadedEventStart;
2003+
}
2004+
if (window.performance.timing.loadEventEnd && window.performance.timing.loadEventStart) {
2005+
trace.apm_metrics.load_event_end = window.performance.timing.loadEventEnd - window.performance.timing.loadEventStart;
2006+
}
2007+
if (Object.keys(trace.apm_metrics).length) {
2008+
Countly.report_trace(trace);
2009+
}
2010+
},1);
19702011
});
2012+
}
2013+
2014+
Countly.userData.set("lastServer", window.location.hostname);
2015+
Countly.userData.set("lastVersion", "<%= countlyVersion %>");
2016+
Countly.userData.set("lastEdition", "<%= countlyTypeTrack %>");
2017+
Countly.userData.set("isTrial", <%= countlyTrial %>);
2018+
Countly.userData.set("cpus", <%= cpus %>);
2019+
Countly.userData.push_unique("servers", window.location.hostname);
2020+
Countly.userData.push_unique("versions", "<%= countlyVersion %>");
2021+
Countly.userData.push_unique("editions", "<%= countlyTypeTrack %>");
2022+
Countly.userData.save();
19712023

1972-
//track any clicks to webpages automatically
1973-
Countly.track_clicks();
2024+
<% if (installed) { %>
2025+
Countly.add_event({
2026+
key:"INSTALL"
2027+
});
2028+
<% } %>
2029+
}
19742030

1975-
//track javascript errors
1976-
Countly.track_errors();
2031+
if (countlyGlobal.config.self_tracking) {
2032+
//initializing countly with params
2033+
var Countly2 = Countly.init({
2034+
app_key: countlyGlobal.config.self_tracking,
2035+
url: window.location.origin,
2036+
device_id: countlyGlobal.member.email,
2037+
app_version: "<%= countlyVersion %>",
2038+
interval:1000
2039+
});
19772040

1978-
//display in app messages
1979-
Countly.content.enterContentZone();
1980-
1981-
if (Countly.report_trace && window.performance && window.performance.timing) {
1982-
$(window).on( "load", function(){
1983-
setTimeout(function(){
1984-
var trace = {
1985-
type: "device",
1986-
name: Countly.getViewName(),
1987-
stz: window.performance.timing.navigationStart,
1988-
etz: window.performance.timing.domContentLoadedEventEnd,
1989-
apm_metrics: {}
1990-
};
1991-
if (window.performance.timing.domLoading && window.performance.timing.navigationStart) {
1992-
trace.apm_metrics.first_paint = window.performance.timing.domLoading - window.performance.timing.navigationStart;
1993-
}
1994-
if (window.performance.timing.domContentLoadedEventStart && window.performance.timing.navigationStart) {
1995-
trace.apm_metrics.first_contentful_paint = window.performance.timing.domContentLoadedEventStart - window.performance.timing.navigationStart;
1996-
}
1997-
if (window.performance.timing.domInteractive && window.performance.timing.navigationStart) {
1998-
trace.apm_metrics.dom_interactive = window.performance.timing.domInteractive - window.performance.timing.navigationStart;
1999-
}
2000-
if (window.performance.timing.domContentLoadedEventEnd && window.performance.timing.domContentLoadedEventStart) {
2001-
trace.apm_metrics.dom_content_loaded_event_end = window.performance.timing.domContentLoadedEventEnd - window.performance.timing.domContentLoadedEventStart;
2002-
}
2003-
if (window.performance.timing.loadEventEnd && window.performance.timing.loadEventStart) {
2004-
trace.apm_metrics.load_event_end = window.performance.timing.loadEventEnd - window.performance.timing.loadEventStart;
2005-
}
2006-
if (Object.keys(trace.apm_metrics).length) {
2007-
Countly.report_trace(trace);
2008-
}
2009-
},1);
2010-
});
2011-
}
2041+
//track sessions automatically
2042+
Countly2.track_sessions();
20122043

2013-
Countly.userData.set("lastServer", window.location.hostname);
2014-
Countly.userData.set("lastVersion", "<%= countlyVersion %>");
2015-
Countly.userData.set("lastEdition", "<%= countlyTypeTrack %>");
2016-
Countly.userData.set("isTrial", <%= countlyTrial %>);
2017-
Countly.userData.set("cpus", <%= cpus %>);
2018-
Countly.userData.push_unique("servers", window.location.hostname);
2019-
Countly.userData.push_unique("versions", "<%= countlyVersion %>");
2020-
Countly.userData.push_unique("editions", "<%= countlyTypeTrack %>");
2021-
Countly.userData.save();
2022-
2023-
<% if (installed) { %>
2024-
Countly.add_event({
2025-
key:"INSTALL"
2026-
});
2027-
<% } %>
2044+
//track pageviews automatically
2045+
Countly2.track_pageview(Countly.getViewName());
2046+
2047+
$(window).on('hashchange', function() {
2048+
Countly2.track_pageview(Countly.getViewName());
2049+
});
2050+
2051+
//display in app messages
2052+
if (Countly2.content.enterContentZone) {
2053+
Countly2.content.enterContentZone();
20282054
}
2029-
</script>
2030-
<% } %>
2055+
2056+
Countly2.user_details({
2057+
"name": countlyGlobal.member.full_name || "",
2058+
"username": countlyGlobal.member.username || "",
2059+
"email": countlyGlobal.member.email
2060+
});
2061+
}
2062+
</script>
20312063
<% } %>
20322064
<script type='text/javascript'>
20332065
app.recordEvent = function (event) {

plugins/plugins/frontend/public/javascripts/countly.views.js

+11
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,17 @@
11701170
}
11711171
});
11721172

1173+
var appList = [{value: "", label: jQuery.i18n.map["configs.frontend-self_tracking.none"]}];
1174+
for (var a in countlyGlobal.apps) {
1175+
appList.push({value: countlyGlobal.apps[a].key, label: countlyGlobal.apps[a].name});
1176+
}
1177+
1178+
app.configurationsView.registerInput("frontend.self_tracking", {
1179+
input: "el-select",
1180+
attrs: {},
1181+
list: appList
1182+
});
1183+
11731184
app.configurationsView.registerStructure("api", {
11741185
description: "configs.api.description",
11751186
groups: [

plugins/plugins/frontend/public/localization/plugins.properties

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ configs.no-theme = Default Theme
6464
configs.frontend-code = Show Code Generator for SDK integration
6565
configs.frontend-offline_mode = Offline mode
6666
configs.frontend-countly_tracking = Countly
67+
configs.frontend-self_tracking = Self tracking using Countly
68+
configs.frontend-self_tracking.none = -- Not tracked --
6769
configs.security-login_tries = Allowed login attempts
6870
configs.security-login_wait = Incorrect login block time increment
6971
configs.security-dashboard_additional_headers = Additional Dashboard HTTP Response headers
@@ -175,7 +177,7 @@ configs.help.frontend-countly_tracking = When enabled, Countly will be activated
175177
configs.help.frontend-production = Initial load of dashboard should be faster, due to smaller files and smaller file amount, but when developing a plugin, you need to regenerate them to see changes
176178
configs.help.frontend-theme = Selected theme will be available server-wide, for all apps and users
177179
configs.help.frontend-session_timeout = User will be forced to logout after session timeout (in minutes) of inactivity. If you want to disable force logout, set to 0.
178-
configs.help.frontend-google_maps_api_key = Google requires an API key for Geocharts visualization used in views such as Overview and Analytics > Countries. Provide your API key to use this visualization without any limitations.<br/><a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Learn how to get your API key.</a>
180+
configs.help.frontend-self_tracking = If you want to track usage of this server and users that are using the dashboard, select an app where to collect this data. Make sure to create a new app specifically for this purpose, or else you would merge collected data with existing. Data will only be stored on this server and will not be sent anywhere else. By selecting an app, you will enabling tracking of this server and it will count towards your datapoint quota. The scale of datapoints will depend on your user count and often usage of this dashboard.
179181
configs.help.security-login_tries = Account will be blocked for some time after provided number of incorrect login attempts. See below for time increments.
180182
configs.help.security-login_wait = Incremental period of time account is blocked after provided number of incorrect login attempts (in seconds)
181183
configs.help.security-password_rotation = Amount of previous passwords user should not be able to reuse

0 commit comments

Comments
 (0)