Has anyone ever queried the GTM JS datalayer directly from PHP? So far I can't find anything by searching Google etc.
Here's some context for readers:
This approach may well be arse-about-face as I could probably also get such data from a Cookie within the domain BUT for interest sake I thought I'd go down this PHP route.
The GTM datalayer is a Javascript variable that exists only in the rendered frontend code. Since PHP runs on the server end of things it does not have access to the datalayer.
Well, technically you could do funny things like creating an AJAX call in the frontend to retrieve the page with the dataLayer and parse it, but that would be a very awkward way of doing things; it would be probably easier to hook into the serverside process that creates the dataLayer code in the first place.
If you want to get creative you could eg build a basic API of sorts that puts the datalayer values in a JSON object and load that from both your WP and .net pages - dataLayer as a service, so to speak. That still seems better than having your WP page scraping the .net app (which seems to be the only alternative).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.