Adsense Script From Functions.php

Can someone please advise how to call adsense script in a certain place of the body of the page? For example, after a specific class or tag (after title tag) ?

This is the function I’m using in child themes function.php file.

    function adsense_script() {

    $path = $_SERVER['REQUEST_URI'];
    $find = 'sdm';
    $pos = strpos($path, $find);
    if ($pos !== false) {

    <Script> 
    //adsense script
    </Script>
    <?php
    }
    }

I tried following, but it does not display the ads properly.

   add_action( 'wp_body_open', 'adsense_script' );