示例代码:
<?php
if ( function_exists( 'wp_enqueue_script' ) ) {
wp_enqueue_script( 'monsterinsights-gtag', plugins_url( '/js/dist/gtag.js', __FILE__ ), array( 'jquery' ), MONSTERINSIGHTS_VERSION, true );
wp_add_inline_script( 'monsterinsights-gtag', 'window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', '' . $ua_code . '');' );
}
?>
<?php
if ( function_exists( 'wp_enqueue_script' ) ) {
wp_enqueue_script( 'gadwp-gtag', plugins_url( '/js/gtag.js', __FILE__ ), array( 'jquery' ), GADWP_CURRENT_VERSION, true );
wp_add_inline_script( 'gadwp-gtag', 'window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', '' . gadwp_get_trackingcode() . '');' );
}
?>
<?php
if ( function_exists( 'wp_enqueue_script' ) ) {
wp_enqueue_script( 'analytify-gtag', plugins_url( '/dist/js/gtag.js', __FILE__ ), array( 'jquery' ), ANALYTIFY_PLUGIN_VERSION, true );
wp_add_inline_script( 'analytify-gtag', 'window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', '' . $tracking_code . '');' );
}
?>