install Segment on WordPress

add that code to a js in your theme folder (or child theme if you’re using it). for this example I named the script “analytics.js” and put it in a directory called “js” in my child theme folder.

Now register and enqueue the file by placing this code in your functions.php

function wpse_load_script()
{
    // Register the script like this:
    wp_register_script( 'analytics-script', get_stylesheet_directory_uri() . '/js/analytics.js', array( 'jquery' ) );

    // You can then enqueue the script:
    wp_enqueue_script( 'analytics-script' );

}
add_action( 'wp_enqueue_scripts', 'wpse_load_script' );

tech