L
L
lorashfuko2018-08-18 10:47:44
JavaScript
lorashfuko, 2018-08-18 10:47:44

How to fix Parse error. ',' expected?

There is an article that describes how to catch 404 in analytics systems through GTM. But when publishing, GTM gives an error and does not publish changes "JavaScript compiler error on line 3, character 19. Parse error. ',' expected"
Judging by the error, he does not like the comma, tell me how to fix it.
In the article itself, comments are closed, so I can’t ask the author.
Here is the code

function() {
  var req = [Http Request];
  try {
    req.open('GET', '[Page URL]', false);
    req.send('');
  } catch (e) {
    success = false;
    error_msg = "Error: " + e;
  }

  return req.status;
}

Solution
In the article in the listing [Http Request] and [Page URL], but you need {{Http Request}} and {{Page URL}}
function() {
  var req = {{Http Request}};

  try {
    req.open('GET', '{{Page URL}}', false);
    req.send('');
  } catch (e) {
    success = false;
    error_msg = "Error: " + e;
  }

  return req.status;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Zharov, 2018-08-18
@lorashfuko

compare in the article the code in the listing and the code on the screen below the listing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question