cookie
_satellite.cookie オブジェクトには、タグルールが参照できるCookieを書き込み、編集、または削除できるメソッドが含まれています。 これはjs-cookieの部分的なコピーで、そのライブラリの多くのコア機能を含んでいます。
cookie.set()
set() メソッドは、タグプロパティが参照できるCookieを書き込みます。
_satellite.cookie.set(name: string, value: string, attributes?: {
expires?: number | Date;
path?: string;
domain?: string;
secure?: boolean;
sameSite?: 'Strict' | 'Lax' | 'None';
}): string
次のメソッドパラメーターを使用できます。
名前
タイプ
必須
説明
namestring○
Cookieの名前。
valuestring○
Cookieの値
attributesobject×
Cookieに付与する追加属性。
attributes オブジェクトは次のプロパティをサポートしています。
属性名
タイプ
必須
デフォルト
説明
pathstring×
サイト全体で表示されるCookie
ドメイン上のCookieが表示される場所です。
domainstring×
作成されたドメインに表示されるCookie
Cookieが表示される有効なドメイン(サブドメインの有無にかかわらず)。 サブドメインなしでドメインが含まれている場合、そのドメインのすべてのサブドメインにCookieが表示されます。
secureboolean×
属性セットがありません
Cookieに安全なプロトコル (
https://)が必要かどうかを判断します。 省略した場合、セキュアなプロトコルの要件はありません。sameSite'Strict' | 'Lax' | 'None'×
属性セットがありません
// Sets a cookie valid across the entire site, expires on session close
_satellite.cookie.set('simple_session_cookie', 'value');
// Sets a cookie that expires 7 days from now, valid across the entire site
_satellite.cookie.set('seven_day_cookie', 'value', { expires: 7 });
// Sets a cookie that expires 14 days from now, valid only on the current page
_satellite.cookie.set('page_specific_cookie', 'value', { expires: 14, path: '/' });
// Cross-site compatible cookie (requires HTTPS)
_satellite.cookie.set('cross_site_cookie', 'value', { secure: true, sameSite: 'None' });
このメソッドを呼び出すと、目的のCookieが書き込まれ、書き込まれたシリアル化されたCookie文字列が返されます。 この文字列は、主にデバッグまたはログ記録の目的で使用されます。
'written_cookie=value; path=/'
TIP
以前のバージョンのタグオブジェクトは
_satellite.setCookie()を使用していました。 setCookie() メソッドは、_satellite.cookie.set()のために非推奨(廃止予定)です。cookie.get()
get() メソッドはCookie値を返します。
_satellite.cookie.get(name: string): string | undefined;
名前
タイプ
必須
説明
namestring○
値を取得するCookie名(大文字と小文字を区別します)。
cookie名が存在する場合は、cookie値を返します。 Cookie名が存在しない場合は、undefinedを返します。
TIP
以前のバージョンのタグオブジェクトは
_satellite.getCookie()を使用していました。 getCookie() メソッドは、_satellite.cookie.get()のために非推奨(廃止予定)です。cookie.remove()
remove() メソッドは、設定したCookieを削除します。
_satellite.cookie.remove(name: string, attributes?: {
path?: string;
domain?: string;
}): void
名前
タイプ
必須
説明
namestring○
削除するCookie名。
attributesobject×
削除するCookieに関連付けられている属性。
pathまたはdomain属性を使用してCookieを設定する場合は、Cookieを削除するときに同じ属性を含めます。 これらの属性を含めないと、Cookieは削除されません。// Creates a session cookie
_satellite.cookie.set('session_cookie', 'Cookie value');
// Removes the above cookie
_satellite.cookie.remove('session_cookie');
// Creates a cookie that is only visible on the current page
_satellite.cookie.set('page_specific_cookie', 'value', { path: '/' });
// This remove method does nothing because it does not match the path and domain attributes of the cookie set
_satellite.cookie.remove('page_specific_cookie');
// This remove method works correctly for the page-specific cookie
_satellite.cookie.remove('page_specific_cookie', { path: '/' });
TIP
以前のバージョンのタグオブジェクトは
_satellite.removeCookie()を使用していました。 removeCookie() メソッドは、_satellite.cookie.remove()のために非推奨(廃止予定)です。recommendation-more-help
experience-platform-help-collection