@formo/analytics 1.16.17 → 1.16.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formo/analytics",
3
- "version": "1.16.17",
3
+ "version": "1.16.19",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/getformo/sdk.git"
@@ -7,9 +7,8 @@ const generateAnonymousId = (key: string): AnonymousID => {
7
7
  if (storedAnonymousId && typeof storedAnonymousId === "string")
8
8
  return storedAnonymousId as AnonymousID;
9
9
  const newAnonymousId = generateNativeUUID();
10
- console.log("cookie set", key, newAnonymousId);
11
10
  cookie().set(key, newAnonymousId, {
12
- expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365).toISOString(), // 1 year
11
+ maxAge: Date.now() + 1000 * 60 * 60 * 24 * 365, // 1 year
13
12
  domain: getCookieDomain(),
14
13
  path: "/",
15
14
  });
@@ -18,17 +17,17 @@ const generateAnonymousId = (key: string): AnonymousID => {
18
17
 
19
18
  function getCookieDomain(hostname: string = window.location.hostname): string {
20
19
  // Special cases
21
- if (hostname === "localhost" || /^\d{1,3}(\.\d{1,3}){3}$/.test(hostname)) {
20
+ if (
21
+ hostname.includes("localhost") ||
22
+ /^\d{1,3}(\.\d{1,3}){3}$/.test(hostname)
23
+ ) {
22
24
  // Localhost or IP address
23
25
  return "";
24
26
  }
25
27
 
26
28
  const parts = hostname.split(".");
27
- if (parts.length >= 2) {
28
- return `.${parts.slice(-2).join(".")}`; // e.g. example.com
29
- }
30
-
31
- return "";
29
+ if (parts.includes("www")) parts.splice(parts.indexOf("www"), 1);
30
+ return `.${parts.join(".")}`;
32
31
  }
33
32
 
34
33
  export { generateAnonymousId, getCookieDomain };
@@ -4,7 +4,7 @@ import { CookieOptions } from "../type";
4
4
  class CookieStorage extends StorageBlueprint {
5
5
  public override isAvailable(): boolean {
6
6
  return (
7
- typeof document !== "undefined" && typeof document.cookie !== "undefined"
7
+ typeof document !== "undefined" && typeof document.cookie === "string"
8
8
  );
9
9
  }
10
10
 
@@ -25,8 +25,7 @@ class CookieStorage extends StorageBlueprint {
25
25
  )}`;
26
26
  if (maxAge) {
27
27
  cookie += "; max-age=" + maxAge;
28
- }
29
- if (expires) {
28
+ } else if (expires) {
30
29
  cookie += "; expires=" + expires;
31
30
  }
32
31
  if (path) {
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '1.16.17';
2
+ export const version = '1.16.19';