Spaces:
Running
Running
feat: Add piwik
Browse files- public/piwik.js +49 -0
- src/tutorial/__init__.py +2 -1
- src/tutorial/example.py +6 -1
- src/tutorial/utils.py +4 -0
public/piwik.js
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function (window, document, dataLayerName, id) {
|
2 |
+
(window[dataLayerName] = window[dataLayerName] || []),
|
3 |
+
window[dataLayerName].push({
|
4 |
+
start: new Date().getTime(),
|
5 |
+
event: "stg.start",
|
6 |
+
});
|
7 |
+
var scripts = document.getElementsByTagName("script")[0],
|
8 |
+
tags = document.createElement("script");
|
9 |
+
function stgCreateCookie(a, b, c) {
|
10 |
+
var d = "";
|
11 |
+
if (c) {
|
12 |
+
var e = new Date();
|
13 |
+
e.setTime(e.getTime() + 24 * c * 60 * 60 * 1e3),
|
14 |
+
(d = "; expires=" + e.toUTCString());
|
15 |
+
f = "; SameSite=Strict";
|
16 |
+
}
|
17 |
+
document.cookie = a + "=" + b + d + f + "; path=/";
|
18 |
+
}
|
19 |
+
var isStgDebug =
|
20 |
+
(window.location.href.match("stg_debug") ||
|
21 |
+
document.cookie.match("stg_debug")) &&
|
22 |
+
!window.location.href.match("stg_disable_debug");
|
23 |
+
stgCreateCookie("stg_debug", isStgDebug ? 1 : "", isStgDebug ? 14 : -1);
|
24 |
+
var qP = [];
|
25 |
+
dataLayerName !== "dataLayer" && qP.push("data_layer_name=" + dataLayerName),
|
26 |
+
isStgDebug && qP.push("stg_debug");
|
27 |
+
var qPString = qP.length > 0 ? "?" + qP.join("&") : "";
|
28 |
+
(tags.async = !0),
|
29 |
+
(tags.src =
|
30 |
+
"https://stria03dye.containers.piwik.pro/" + id + ".js" + qPString),
|
31 |
+
scripts.parentNode.insertBefore(tags, scripts);
|
32 |
+
!(function (a, n, i) {
|
33 |
+
a[n] = a[n] || {};
|
34 |
+
for (var c = 0; c < i.length; c++)
|
35 |
+
!(function (i) {
|
36 |
+
(a[n][i] = a[n][i] || {}),
|
37 |
+
(a[n][i].api =
|
38 |
+
a[n][i].api ||
|
39 |
+
function () {
|
40 |
+
var a = [].slice.call(arguments, 0);
|
41 |
+
"string" == typeof a[0] &&
|
42 |
+
window[dataLayerName].push({
|
43 |
+
event: n + "." + i + ":" + a[0],
|
44 |
+
parameters: [].slice.call(arguments, 1),
|
45 |
+
});
|
46 |
+
});
|
47 |
+
})(i[c]);
|
48 |
+
})(window, "ppms", ["tm", "cm"]);
|
49 |
+
})(window, document, "dataLayer", "c0650426-566c-43ff-b829-ad1b273a31ea");
|
src/tutorial/__init__.py
CHANGED
@@ -16,6 +16,7 @@ hdrs = (
|
|
16 |
utils.alpine(),
|
17 |
fh.Script(src="/script.js"),
|
18 |
fh.Script("init_main_page()"),
|
|
|
19 |
)
|
20 |
html_kv = {
|
21 |
"x-data": """{
|
@@ -98,7 +99,7 @@ def get_example(name):
|
|
98 |
|
99 |
|
100 |
def start():
|
101 |
-
fh.serve("tutorial.__init__", app="get_app")
|
102 |
|
103 |
|
104 |
if __name__ == "__main__":
|
|
|
16 |
utils.alpine(),
|
17 |
fh.Script(src="/script.js"),
|
18 |
fh.Script("init_main_page()"),
|
19 |
+
utils.piwik(),
|
20 |
)
|
21 |
html_kv = {
|
22 |
"x-data": """{
|
|
|
99 |
|
100 |
|
101 |
def start():
|
102 |
+
fh.serve("tutorial.__init__", app="get_app", reload=False)
|
103 |
|
104 |
|
105 |
if __name__ == "__main__":
|
src/tutorial/example.py
CHANGED
@@ -49,7 +49,12 @@ class Example:
|
|
49 |
def create_routes(self, main_app: fh.FastHTML):
|
50 |
sub_app, slug = self.module.app, self.slug
|
51 |
sub_app.htmlkw = main_app.htmlkw
|
52 |
-
sub_app.hdrs += (
|
|
|
|
|
|
|
|
|
|
|
53 |
main_app.mount(f"/{slug}", sub_app)
|
54 |
main_app.get(f"/{slug}")(self.main_page)
|
55 |
|
|
|
49 |
def create_routes(self, main_app: fh.FastHTML):
|
50 |
sub_app, slug = self.module.app, self.slug
|
51 |
sub_app.htmlkw = main_app.htmlkw
|
52 |
+
sub_app.hdrs += (
|
53 |
+
utils.alpine(),
|
54 |
+
fh.Script(src="/script.js"),
|
55 |
+
fh.Script(f"init_sub_page('{slug}')"),
|
56 |
+
utils.piwik(),
|
57 |
+
)
|
58 |
main_app.mount(f"/{slug}", sub_app)
|
59 |
main_app.get(f"/{slug}")(self.main_page)
|
60 |
|
src/tutorial/utils.py
CHANGED
@@ -56,3 +56,7 @@ def concat(*elts, sep=" | "):
|
|
56 |
for elt in elts[1:]:
|
57 |
out += [sep, elt]
|
58 |
return out
|
|
|
|
|
|
|
|
|
|
56 |
for elt in elts[1:]:
|
57 |
out += [sep, elt]
|
58 |
return out
|
59 |
+
|
60 |
+
|
61 |
+
def piwik():
|
62 |
+
return Script(src="piwik.js")
|