Data Layer Meta Field
WordPress plugin: add a per-page/post field that pushes custom JSON to the GTM dataLayer
by Hagop Imasdounian · github.com/hagopimasdounian/data-layer-meta-field
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/hagopimasdounian/data-layer-meta-field/archive/refs/heads/master.zipA tiny, single-file WordPress plugin that adds a per-page/per-post field for pushing custom values into the Google Tag Manager / analytics dataLayer.
Add structured JSON (or a value) to any page or post in the editor, and the plugin injects a dataLayer.push(...) for it in the site footer — no theme edits, no code, no per-page hardcoding.
What it does
- Adds a "Data Layer Field" meta box to the
postandpageeditors. - Stores whatever you enter in post meta (
_data_layer_value). - On the frontend (singular views), outputs:
<script>window.dataLayer = window.dataLayer || []; dataLayer.push( <your value> );</script>so GTM and other tags can read it.
Install
- Copy
data-layer-meta-field.phpintowp-content/plugins/data-layer-meta-field/(or zip the folder and upload it via Plugins → Add New → Upload). - Activate Data Layer Meta Field in the WordPress admin.
Usage
- Edit any page or post.
- In the Data Layer Field box, paste a JSON object, e.g.:
{ "event": "page_meta", "pageType": "product", "brand": "Rolex" } - Update the page. View it on the frontend — the object is pushed to
window.dataLayerand available to GTM.
The value is output as-is into a
dataLayer.push()call, so enter valid JSON (or a valid JS expression). Input is admin-only and nonce-protected on save.
Notes
- No settings page, no dependencies, no external calls.
- Works alongside GTM; it does not install GTM for you.
License
MIT