I need to capture text from the file saved under URL (ex. https://fiddle.jshell.net/robots.txt) And return it under the function.
What is on my mind:
function(){
var url = 'https://fiddle.jshell.net/robots.txt'
var storedText;
fetch(url)
.then(function(response) {
response.text().then(function(text) {
storedText = text;
done();
});
});
function done() {
return storedText;
}
});
Unfortunately this function is not working. I received an error: Error at line 2, character 2: Parse error. primary expression expected Type: JavaScript compiler error
This should be used as a Custom JavasSript Variable in Google Tag Manager
Also this How do I return the response from an asynchronous call? is not explaining my issue and all solutions were checked by me, nothing worked due Parse error or console error.
I have to use GTM custom JavaScrip Variable, I can use anything else. Simpler JS than better.