Current collected state Current
Observed since 20 Oct, 21:32 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Vue 3 hooks for handling UTM parameters in URLs and storing them in cookies
Vue 3 hook,用于处理 URL 中的 utm_source 参数并存储到 cookie 中。
npm install 9466-utm-tracker
这个 hook 需要在 Vue Router 环境中使用,因为它依赖于 Vue Router 来获取 URL 参数。
// 在你的 router/index.ts 中
import { createRouter, createWebHistory } from "vue-router";
const router = createRouter({
history: createWebHistory(),
routes: [
// 你的路由配置
],
});
export default router;
import { useUtm } from "9466-utm-tracker";
export default {
setup() {
const { utmSource } = useUtm({
cookieExpireDays: 30, // 可选,默认30天
cookieDomain: ".example.com", // 可选
cookiePath: "/", // 可选,默认'/'
});
// utmSource 是一个 ref 对象,包含 utm_source 的值
console.log(utmSource.value); // 例如: 'google'
},
};
hook 会自动:
支持以下格式的 URL:
http://example.com/#/path?utm_source=googlehttp://example.com/path?utm_source=googleutm_source 参数会直接存储在名为 _9466_utm 的 cookie 中,例如:
_9466_utm=google
主函数,返回一个包含 utm_source 和相关方法的对象。
interface UseUtmOptions {
cookieExpireDays?: number; // cookie 过期天数,默认 30
cookieDomain?: string; // cookie 域名
cookiePath?: string; // cookie 路径
}
{
utmSource: Ref<string>; // 响应式的 utm_source 值
getUtmFromUrl: () => string; // 从当前 URL 获取 utm_source 的方法
getUtmFromCookie: () => string; // 从 cookie 获取 utm_source 的方法
}
MIT
Download counts and popularity will appear here as the collector receives them.
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 21:32 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:2cf1ff665686ac5e39b96bb5708d4a75b995723f6b86260627e5587df0db49d7