add dynamic analitics tracking to home page

This commit is contained in:
Cyberes 2023-08-23 23:27:33 -06:00
parent c2b0fa1cf5
commit f7743ade89
4 changed files with 28 additions and 19 deletions

View File

@ -11,6 +11,21 @@ token_limit: 7777
backend_url: https://10.0.0.86:8083 backend_url: https://10.0.0.86:8083
llm_middleware_name: proxy.chub-archive.evulid.cc llm_middleware_name: proxy.chub-archive.evulid.cc
analytics_tracking_code: |
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function () {
var u = "https://mato.evulid.cc/";
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setSiteId', '10']);
var d = document,
g = d.createElement('script'),
s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
})();
## STATS ## ## STATS ##

View File

@ -9,6 +9,7 @@ config_default_vars = {
'load_num_prompts': False, 'load_num_prompts': False,
'show_num_prompts': True, 'show_num_prompts': True,
'show_uptime': True, 'show_uptime': True,
'analytics_tracking_code': '',
} }
config_required_vars = ['token_limit', 'concurrent_gens', 'mode', 'llm_middleware_name'] config_required_vars = ['token_limit', 'concurrent_gens', 'mode', 'llm_middleware_name']

View File

@ -1,3 +1,4 @@
import collections
import json import json
import os import os
import sys import sys
@ -93,7 +94,7 @@ app.register_blueprint(bp, url_prefix='/api/v1/')
def home(): def home():
if not opts.full_client_api: if not opts.full_client_api:
opts.full_client_api = f'https://{request.headers.get("Host")}/{opts.frontend_api_client.strip("/")}' opts.full_client_api = f'https://{request.headers.get("Host")}/{opts.frontend_api_client.strip("/")}'
stats = generate_stats() stats = collections.OrderedDict(sorted(generate_stats().items()))
if not bool(redis.get('backend_online')) or not stats['online']: if not bool(redis.get('backend_online')) or not stats['online']:
running_model = estimated_wait_sec = 'offline' running_model = estimated_wait_sec = 'offline'
@ -101,8 +102,14 @@ def home():
running_model = opts.running_model running_model = opts.running_model
estimated_wait_sec = f"{stats['estimated_wait_sec']} seconds" estimated_wait_sec = f"{stats['estimated_wait_sec']} seconds"
if len(config['analytics_tracking_code']):
analytics_tracking_code = f"<script>\n{config['analytics_tracking_code']}\n</script>"
else:
analytics_tracking_code = ''
return render_template('home.html', return render_template('home.html',
llm_middleware_name=config['llm_middleware_name'], llm_middleware_name=config['llm_middleware_name'],
analytics_tracking_code=analytics_tracking_code,
current_model=running_model, current_model=running_model,
client_api=opts.full_client_api, client_api=opts.full_client_api,
estimated_wait=estimated_wait_sec, estimated_wait=estimated_wait_sec,

View File

@ -1,24 +1,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<title>{{ llm_middleware_name }}</title>
<meta content="width=device-width, initial-scale=1" name="viewport"/> <meta content="width=device-width, initial-scale=1" name="viewport"/>
<script> {{ analytics_tracking_code|safe }}
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function () {
var u = "https://mato.evulid.cc/";
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setSiteId', '10']);
var d = document,
g = d.createElement('script'),
s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
})();
</script>
<style> <style>
.container { .container {
padding: 1em 3em; padding: 1em 3em;
@ -65,7 +51,7 @@
<br><br> <br><br>
<pre id="json">{{ stats_json }}</pre> <pre id="json">{{ stats_json|safe }}</pre>
</div> </div>
</body> </body>