PHPackages                             clicktrail/twig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. clicktrail/twig

ActiveLibrary[Templating &amp; Views](/categories/templating)

clicktrail/twig
===============

Render-only Twig 3 helpers for ClickTrail attribution: head loader tag, hidden form inputs, consent state attributes.

v0.1.0(yesterday)00MITPHPPHP &gt;=8.1CI passing

Since Aug 24Pushed todayCompare

[ Source](https://github.com/vizuh/clicktrail-twig)[ Packagist](https://packagist.org/packages/clicktrail/twig)[ RSS](/packages/clicktrail-twig/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

[English](README.md) | [Português](README.pt-BR.md) | [Deutsch](README.de.md) | [中文](README.zh-CN.md)

**clicktrail/twig**

Render-only [Twig 3](https://twig.symfony.com/) helpers for ClickTrail attribution — your adapter precomputes the values, these functions only render and escape the markup.

[![CI](https://github.com/vizuh/clicktrail-twig/actions/workflows/ci.yml/badge.svg)](https://github.com/vizuh/clicktrail-twig/actions/workflows/ci.yml)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)

Index
-----

[](#index)

- [Why](#why)
- [Installation](#installation)
- [Quick start](#quick-start)
- [Loader script tag](#loader-script-tag)
- [Hidden attribution inputs](#hidden-attribution-inputs)
- [Consent state attributes](#consent-state-attributes)
- [How it differs](#how-it-differs)
- [Testing](#testing)
- [License](#license)

Why
---

[](#why)

Attribution markup usually grows by hand inside templates: copy-pasted loader tags, hidden inputs nobody keeps in sync with the GTM variable list, consent attributes that drift. `clicktrail/twig` gives October components, Craft modules and Symfony bundles one canonical way to render ClickTrail markup — and none of the logic.

Installation
------------

[](#installation)

```
composer require clicktrail/twig
```

Requires PHP &gt;= 8.1, Twig ^3.0, and `clicktrail/php-sdk`.

Quick start
-----------

[](#quick-start)

```
{{ clicktrail_head({script_src: '/ct/loader.js', site_id: site_id}) }}
{# renders  #}
```

That is the whole contract: values in, escaped markup out. No HTTP calls, no storage, no consent judgment — ever.

Loader script tag
-----------------

[](#loader-script-tag)

### `clicktrail_head(array $config): string`

[](#clicktrail_headarray-config-string)

Renders the first-party loader `` tag plus `data-ct-*` configuration attributes. `$config` keys:

- `script_src` (required): URL of the first-party loader script.
- Every other scalar key becomes a `data-ct-` attribute (underscores become hyphens), e.g. `site_id` → `data-ct-site-id`.

```
{{ clicktrail_head({script_src: '/ct/loader.js', site_id: site_id}) }}
{# every scalar key lands as data-ct-; missing script_src renders '' #}
```

Hidden attribution inputs
-------------------------

[](#hidden-attribution-inputs)

### `clicktrail_hidden_attribution_inputs(array $attribution): string`

[](#clicktrail_hidden_attribution_inputsarray-attribution-string)

Renders hidden `` fields carrying the full attribution context into forms — same field list as the ClickTrail GTM attribution variables and the October `AttributionHidden` component: visitor/session/event/site IDs, `utm_*` values, all 10 ad click IDs, landing page, initial referrer, and consent state.

`$attribution` is a flat precomputed map, e.g. `['visitor_id' => ..., 'session_id' => ..., 'event_id' => ..., 'site_id' => ..., 'utm_source' => ..., 'gclid' => ..., 'landing_page' => ..., 'initial_referrer' => ..., 'consent_state' => 'granted']`. Empty values are skipped.

```

    {{ clicktrail_hidden_attribution_inputs(attribution)|raw }}

```

Consent state attributes
------------------------

[](#consent-state-attributes)

### `clicktrail_consent_state(array $snapshot): string`

[](#clicktrail_consent_statearray-snapshot-string)

Renders normalized consent state as `data-ct-consent-*` attributes from a `ClickTrailConsentSnapshot`-shaped array (functional, analytics\_storage, advertising\_storage, ad\_user\_data, ad\_personalization). Intended for use inside an opening tag:

```

```

Unknown or missing keys render nothing — the function makes no consent judgment of its own.

How it differs
--------------

[](#how-it-differs)

Typical template helpersclicktrail/twigFetch, track or persist inside the templateRender only: never HTTP, never storage, never side effectsEvaluate whether consent was legally validRenders whatever snapshot the caller passes inAd-hoc escaping per helperEvery dynamic value through `htmlspecialchars(..., ENT_QUOTES)`Positioning: layer-1 framework package (ADR-0001 polyrepo). Platform adapters own the effects (clock, storage, HTTP, consent resolution); this package owns none of them.

Testing
-------

[](#testing)

```
php tests/_runner.php   # standalone assert runner, no composer install needed
```

Or inside a container:

```
podman run --rm -v "$PWD":/app:Z wordpress:php8.3-apache php tests/_runner.php
```

License
-------

[](#license)

MIT © 2026 Vizuh OÜ.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20295730?v=4)[Hugo ](/maintainers/Atroci)[@Atroci](https://github.com/Atroci)

---

Top Contributors

[![Atroci](https://avatars.githubusercontent.com/u/20295730?v=4)](https://github.com/Atroci "Atroci (7 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

analyticsattributionclickstreamconsent-managementconversion-trackingfirst-party-datagdprmarketing-analyticsphptemplate-helperstwigtwig-extensionutm

### Embed Badge

![Health badge](/badges/clicktrail-twig/health.svg)

```
[![Health](https://phpackages.com/badges/clicktrail-twig/health.svg)](https://phpackages.com/packages/clicktrail-twig)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.7M3.5k](/packages/craftcms-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
