Adrien Denat commited on
Commit
b3563cb
1 Parent(s): da1e5da

add deprecated GA v3 (#158)

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. src/app.html +28 -0
  3. src/hooks.server.ts +8 -3
.env CHANGED
@@ -16,6 +16,7 @@ PUBLIC_ASSISTANT_MESSAGE_TOKEN=<|assistant|>
16
  PUBLIC_SEP_TOKEN=</s>
17
  PUBLIC_PREPROMPT="Below are a series of dialogues between various people and an AI assistant. The AI tries to be helpful, polite, honest, sophisticated, emotionally aware, and humble-but-knowledgeable. The assistant is happy to help with almost anything, and will do its best to understand exactly what is needed. It also tries to avoid giving false or misleading information, and it caveats when it isn't entirely sure about the right answer. That said, the assistant is practical and really does its best, and doesn't let caution get too much in the way of being useful."
18
  PUBLIC_GOOGLE_ANALYTICS_ID=#G-XXXXXXXX / Leave empty to disable
 
19
 
20
  # Copy this in .env.local with and replace "hf_<token>" your HF token from https://huggingface.co/settings/token
21
  # You can also change the model from OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5 to your own model
 
16
  PUBLIC_SEP_TOKEN=</s>
17
  PUBLIC_PREPROMPT="Below are a series of dialogues between various people and an AI assistant. The AI tries to be helpful, polite, honest, sophisticated, emotionally aware, and humble-but-knowledgeable. The assistant is happy to help with almost anything, and will do its best to understand exactly what is needed. It also tries to avoid giving false or misleading information, and it caveats when it isn't entirely sure about the right answer. That said, the assistant is practical and really does its best, and doesn't let caution get too much in the way of being useful."
18
  PUBLIC_GOOGLE_ANALYTICS_ID=#G-XXXXXXXX / Leave empty to disable
19
+ PUBLIC_DEPRECATED_GOOGLE_ANALYTICS_ID=#UA-XXXXXXXX-X / Leave empty to disable
20
 
21
  # Copy this in .env.local with and replace "hf_<token>" your HF token from https://huggingface.co/settings/token
22
  # You can also change the model from OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5 to your own model
src/app.html CHANGED
@@ -15,6 +15,7 @@
15
 
16
  // For some reason, Sveltekit doesn't let us load env variables from .env here, so we load it from hooks.server.ts
17
  window.gaId = "%gaId%";
 
18
  </script>
19
  %sveltekit.head%
20
  </head>
@@ -41,5 +42,32 @@
41
  /// TODO: ask the user for their consent and update this with gtag('consent', 'update')
42
  }
43
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  </body>
45
  </html>
 
15
 
16
  // For some reason, Sveltekit doesn't let us load env variables from .env here, so we load it from hooks.server.ts
17
  window.gaId = "%gaId%";
18
+ window.gaIdDeprecated = "%gaIdDeprecated%";
19
  </script>
20
  %sveltekit.head%
21
  </head>
 
42
  /// TODO: ask the user for their consent and update this with gtag('consent', 'update')
43
  }
44
  </script>
45
+
46
+ <!-- Google Analytics v3 (deprecated on 1 July 2023) -->
47
+ <script>
48
+ if (window.gaIdDeprecated) {
49
+ (function (i, s, o, g, r, a, m) {
50
+ i["GoogleAnalyticsObject"] = r;
51
+ (i[r] =
52
+ i[r] ||
53
+ function () {
54
+ (i[r].q = i[r].q || []).push(arguments);
55
+ }),
56
+ (i[r].l = 1 * new Date());
57
+ (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
58
+ a.async = 1;
59
+ a.src = g;
60
+ m.parentNode.insertBefore(a, m);
61
+ })(
62
+ window,
63
+ document,
64
+ "script",
65
+ "https://www.google-analytics.com/analytics.js",
66
+ "ganalytics"
67
+ );
68
+ ganalytics("create", window.gaIdDeprecated, "auto");
69
+ ganalytics("send", "pageview");
70
+ }
71
+ </script>
72
  </body>
73
  </html>
src/hooks.server.ts CHANGED
@@ -1,7 +1,10 @@
1
  import { dev } from "$app/environment";
2
  import { COOKIE_NAME } from "$env/static/private";
3
  import type { Handle } from "@sveltejs/kit";
4
- import { PUBLIC_GOOGLE_ANALYTICS_ID } from "$env/static/public";
 
 
 
5
  import { addYears } from "date-fns";
6
 
7
  export const handle: Handle = async ({ event, resolve }) => {
@@ -24,12 +27,14 @@ export const handle: Handle = async ({ event, resolve }) => {
24
  const response = await resolve(event, {
25
  transformPageChunk: (chunk) => {
26
  // For some reason, Sveltekit doesn't let us load env variables from .env in the app.html template
27
- if (replaced || !chunk.html.includes("%gaId%")) {
28
  return chunk.html;
29
  }
30
  replaced = true;
31
 
32
- return chunk.html.replace("%gaId%", PUBLIC_GOOGLE_ANALYTICS_ID);
 
 
33
  },
34
  });
35
 
 
1
  import { dev } from "$app/environment";
2
  import { COOKIE_NAME } from "$env/static/private";
3
  import type { Handle } from "@sveltejs/kit";
4
+ import {
5
+ PUBLIC_GOOGLE_ANALYTICS_ID,
6
+ PUBLIC_DEPRECATED_GOOGLE_ANALYTICS_ID,
7
+ } from "$env/static/public";
8
  import { addYears } from "date-fns";
9
 
10
  export const handle: Handle = async ({ event, resolve }) => {
 
27
  const response = await resolve(event, {
28
  transformPageChunk: (chunk) => {
29
  // For some reason, Sveltekit doesn't let us load env variables from .env in the app.html template
30
+ if (replaced || !chunk.html.includes("%gaId%") || !chunk.html.includes("%gaIdDeprecated%")) {
31
  return chunk.html;
32
  }
33
  replaced = true;
34
 
35
+ return chunk.html
36
+ .replace("%gaId%", PUBLIC_GOOGLE_ANALYTICS_ID)
37
+ .replace("%gaIdDeprecated%", PUBLIC_DEPRECATED_GOOGLE_ANALYTICS_ID);
38
  },
39
  });
40