medelse/utm-cookie-bundle

UtmCookieBundle 是一个用于在存在时将 URL 中的 utm 参数保存到 cookie 的 Symfony Bundle。之后,可以不解析谷歌或其他任何 cookie 就使用 cookie(utm)。

安装次数: 15,273

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 4

公开问题: 1

类型:symfony-bundle

1.0.0 2021-06-11 14:34 UTC

This package is auto-updated.

Last update: 2024-08-26 14:20:44 UTC


README

MedelseUtmCookieBundle 是一个用于在存在时将 URL 中的 utm 参数保存到 cookie 的 Symfony Bundle。之后,可以不解析谷歌或其他任何 cookie 就使用 cookie(utm)。

功能包括

  • 兼容 Symfony 版本 3 & 4

安装

通过 Composer

安装 Bundle

$ composer require medelse/utm-cookie-bundle

在 app/AppKernel.php 中注册 Bundle(Symfony V3)

// app/AppKernel.php

public function registerBundles()
{
    return array(
        // ...
        new Medelse\UtmCookieBundle\MedelseUtmCookieBundle(),
    );
}

在 app/AppKernel.php 中注册 Bundle(Symfony V4)

// config/bundles.php

return [
    // ...
    Medelse\UtmCookieBundle\MedelseUtmCookieBundle::class => ['all' => true],
];

参数

medelse_utm_cookie:
    name: 'utm' #The Name of cookie (default value "utm")
    lifetime: 604800 #The lifetime of cookie in seconds (default 604800 => 7 days)
    path: '/' #The path on the server in which the cookie will be available on (default '/')
    domain: '' #The (sub)domain that the cookie is available to (default '' so use current domain)
    overwrite: true|false #If overwrite all utm values when even one is set in get (default true)
    secure: true|false #Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client (default false)
    httponly: true|false #When TRUE the cookie will be made accessible only through the HTTP protocol (default false)
    auto_init: true|false #If true, run init and create cookie automatically. If false you have to call init manually (default true)

使用方法

公共服务

可用的服务名称是 medelse_utm_cookie.utm_cookie

基本用法

$this->get('medelse_utm_cookie.utm_cookie')->init(); // just init - read utm params and cookie and save new values. (optionnal if auto_init config is TRUE or automatically called when call get() method)
$this->get('medelse_utm_cookie.utm_cookie')->get(); // get all utm cookies as array
$this->get('medelse_utm_cookie.utm_cookie')->get('utm_source'); // get utm_source
$this->get('medelse_utm_cookie.utm_cookie')->get('source'); // get utm_source

许可证

此 Bundle 采用 MIT 许可证。