public function SnippetGenerator::getSnippet in Drupal 8 Google Optimize Hide Page 8
Generate the JS snippet.
Return value
string JS snippet.
File
- src/
Util/ SnippetGenerator.php, line 16
Class
- SnippetGenerator
- Implements Snippet Generator class.
Namespace
Drupal\d8_google_optimize_hide_page\UtilCode
public function getSnippet() : string {
$container_ids = d8_google_optimize_hide_page_container_ids();
$class_name = d8_google_optimize_hide_page_class_name();
$timeout = d8_google_optimize_hide_page_timeout();
$container_ids = array_map(function ($value) {
return "'" . trim($value) . "':true";
}, $container_ids);
$container_str = implode(',', $container_ids);
return sprintf("(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;\n h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};\n (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;\n })(window,document.documentElement,'%s','dataLayer',%d,\n {%s});", $class_name, $timeout, $container_str);
}