Adding initialize to body tag if I am using a specific ACF block

I am making a ACF block that includes a google map and I need to add:

onload="initialize()"

to the body tag.
Can I use PHP to add that code conditionally if a unique ACF block is being used on the page?

I tried this:

function check_if_block_exist($block_handle) {
  $post = get_post(); 

  if(has_blocks($post->post_content)) {
    $blocks = parse_blocks($post->post_content);

    foreach( $blocks as $block ) {
      if($block['blockName'] === $block_handle) {
        return true;
      }
    }
    return false;
  }
}

But it didn’t work.