I’m trying to retrieve value in external javascript file from gtm.
The document structure is as below:
In the index.js, I can find a json and want to get "signup/01" value in the json.
However I cannot see "signup/01" in (index).
Now, I tried to create a tag and custom javascript variable called pageStepId in gtm.
But I cannot get the value properly in the preview.
And I have a custom javascript valuable in gtm and trying to get the value.
var args = document.getElementsByTagName("script"), result = 0; for (var i = 0; i < args.length; i++) { var arg = args[i].innerText.match(/signup\/\d*/g); if (arg != null) { //result = arg[0].replace(/[^\d]/g, ""); result = arg[0]; break; } } return result; } I'm not sure if my approach is wrong or just a tiny mistake. Please help me.




