'prototype.replace() not working in Google Tab Manager

I have a very simple Custom JavaScript variable (which is a small function) with prototype.replace() that returns undefined in GTM:

function(){
  
  var stringElem = {{Click Element}};
    
  return stringElem.replace( 'HTMLSpanElement: ', '' );

}
 

No matter what I do, it returns undefined. {{Click Element}} is in dataLayer and is showing a non-empty string value. What am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source