Skip to main content
Cookbook Marketing GTM4WP

Add Reading Time and Post Details to Your Data Layer with GTM4WP and AI

Reading time, word count, dates, categories or authors in your Tag Manager data layer, turned on after your yes and checked on a post.

Difficulty Intermediate
Time ~10 min

Prerequisites

A site connected to WPVibe running GTM4WP (Google Tag Manager for WordPress) 2.1 or newer (tested on 2.1.1, free) on WordPress 6.9 or newer (tested on 7.1.4), with an administrator account. A Google Tag Manager container already set in GTM4WP.

The prompt
My WordPress site uses GTM4WP (Google Tag Manager for WordPress). Add [what you want to report on, for example reading time, word count, publish date and primary category] to my data layer so I can use it in Tag Manager and GA4.

1. Run discover_abilities with category gtm4wp. If no gtm4wp ability is there, stop and tell me to install or update the free GTM4WP plugin (Google Tag Manager for WordPress, 2.1 or newer, on WordPress 6.9 or newer), or that the site may have switched GTM4WP's abilities off. If the others are there but gtm4wp/update-settings is not, tell me this site keeps GTM4WP's abilities read-only, so the change is made on the GTM4WP settings screen, and stop. Then run gtm4wp/get-status: if containers is empty and placement is not off, tell me GTM4WP writes no data layer until a container is set, so I should add mine first, and stop.
2. Run gtm4wp/get-settings with modules page-variables and include_schema true, and keep its values_hash. Match what I asked for to these options by their labels and descriptions. Show me each match with its label, whether it is already on, and what it adds. If something I asked for has no option, say so.
3. If a match is include-useremail, include-username, include-userid, include-userregdate, include-visitor-ip, include-miscgeo-cloudflare, include-searchdata or include-postmeta, tell me it puts personal or private data into every page, where any tag in my container can read it (custom fields are in the page source, readable by any visitor), and that it usually needs a privacy notice or consent. Leave it out unless I confirm it again. If I do confirm include-postmeta, ask which custom fields to publish and set include-postmeta-keys to them, since leaving it empty publishes every custom field whose name does not start with an underscore.
4. Run gtm4wp/export-settings and keep its answer as the backup of my settings: to undo, send the old values from it with gtm4wp/update-settings after the same confirmation, never with import-settings, which replaces every setting. Show me each option you will change with its current value and its new value, and ask: Confirm this change? Wait for my yes. Then run gtm4wp/update-settings with only those options under values, and expected_hash set to the values_hash from get-settings. If it says the settings changed in between, read them again and ask me again. If it says changing settings through the Abilities API is switched off, tell me to change it on the GTM4WP settings screen and stop. If it lists an option under errors, tell me its message: that option was not saved. Change only the options I agreed to: each checkbox to true, and include-postmeta-keys to the field names I gave.
5. Run get_page_html for [a published post on my site] (if I gave none, find my latest published post with rest_api GET /wp/v2/posts with per_page 1 and use its link) and find the line var dataLayer_content (the answer can be cut short: read on with offset). List each new variable name with its value on that post. This is the page a logged-out visitor gets, so options about the logged-in user (email, user name, user ID, registration date) do not show there, and the role and login state show their logged-out values (visitor-logged-out and logged-out): say so rather than calling them missing. With include-visitor-ip on, visitorIP may be missing or show the address of my server or my CDN, since the site fetches the page itself; real visitors get their own. Search data shows only on search results, and the Cloudflare country only on requests that come through Cloudflare. If none of the others is there, a page cache may be serving an older copy: tell me to clear it.
6. Tell me that to use them, I create a Data Layer Variable in Tag Manager for each name, exactly as written, and add it to my GA4 tags as a parameter (and as a custom dimension in GA4 to see it in reports). Nothing reaches Google Analytics until then.
Already connected?

Skip pasting the full prompt. Drop this into your AI on a site that already has WPVibe:

Run the “Add Reading Time and Post Details to Your Data Layer with GTM4WP and AI” recipe from the WPVibe cookbook on my connected site.

You want to know which kind of content works: long reads or short ones, new posts or old ones, which category or author keeps people reading. GA4 can report on all of it, but only if each page tells Tag Manager those details, and GTM4WP’s list of page variables runs to more than thirty checkboxes.

You say what you want to report on, and the AI matches it to GTM4WP’s page options, shows you what each adds, and turns on only those after your yes. Then it reads one of your posts as a visitor gets it and lists the new data layer variables with their values, ready to use in Tag Manager.

Options that put the visitor’s email, user name, user ID or IP address, or your posts’ custom fields, into the page are personal or private data every tag can read: the prompt explains that and asks again before it turns one on. To see the details in GA4 reports, create a Data Layer Variable for each in Tag Manager and send it with your GA4 tags. GTM4WP writes no data layer until a container is set: to add one, use this recipe.

Outcome

The page details you chose are in every post's data layer, with their variable names listed for Tag Manager.