Skip to content

Commit

Permalink
Merge pull request #7 from dubinc/add-default-path
Browse files Browse the repository at this point in the history
Add default path to cookie
  • Loading branch information
steven-tey authored May 13, 2024
2 parents a082d6a + a375c26 commit 62b2b3b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/script/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// Utility function to set a cookie
function setCookie(key, value, options) {
// options: domain, expires, httpOnly, maxAge, path, sameSite, secure
document.cookie = `${key}=${value}; ${options.domain ? `domain=${options.domain}; ` : ''}${`expires=${new Date(options.expires || Date.now() + COOKIE_EXPIRES).toUTCString()}; `}${options.httpOnly ? 'httpOnly; ' : ''}${options.maxAge ? `max-age=${options.maxAge}; ` : ''}${options.path ? `path=${options.path}; ` : ''}${options.sameSite ? `sameSite=${options.sameSite}; ` : ''}${options.secure ? 'secure;' : ''}`;
document.cookie = `${key}=${value}; ${options.domain ? `domain=${options.domain}; ` : ''}${`expires=${new Date(options.expires || Date.now() + COOKIE_EXPIRES).toUTCString()}; `}${options.httpOnly ? 'httpOnly; ' : ''}${options.maxAge ? `max-age=${options.maxAge}; ` : ''}${`path=${options.path || '/'}`}${options.sameSite ? `sameSite=${options.sameSite}; ` : ''}${options.secure ? 'secure;' : ''}`;
}

// Function to check for {keys} in the URL and update cookie if necessary
Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/generic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { version } from '../package.json';
import { name, version } from '../package.json';
import type { AnalyticsProps } from './types';
import { getScriptSrc, isBrowser } from './utils';

Expand All @@ -15,6 +15,7 @@ function inject(props: AnalyticsProps): void {
const script = document.createElement('script');
script.src = src;
script.defer = true;
script.setAttribute('data-sdkn', name);
script.setAttribute('data-sdkv', version);
script.setAttribute(
'data-cookie-options',
Expand Down

0 comments on commit 62b2b3b

Please sign in to comment.