Title: Conditional google analytics tag
Last modified: August 10, 2021

---

# Conditional google analytics tag

 *  [stuartcr](https://wordpress.org/support/users/stuartcr/)
 * (@stuartcr)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/conditional-google-analytics-tag/)
 * Hello,
 * i would like to active this google tag only on 1 page the contact page(id=313)
 * but this isnt working:
 *     ```
       <?php if ( is_page(313)) {
           echo '<script async src="https://www.googletagmanager.com/gtag/js?id=AW-346653908"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'AW-346653908'); </script>';}
       endif;
       ?>
       ```
   
 * can any one help please?
    -  This topic was modified 4 years, 10 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not an Developing with WordPress
      topic
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fconditional-google-analytics-tag%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  [tugbucket](https://wordpress.org/support/users/tugbucket/)
 * (@tugbucket)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/conditional-google-analytics-tag/#post-14753950)
 * Are you putting this in your functions.php? It’s not going to work there but 
   you can use:
 *     ```
       function add_google_12bn(){
       	if(is_page(18)){
       		echo 'Your Code Here';
       	}
       }
       add_action('wp', 'add_google_12bn');
       ```
   
 * Obviously change you page ID and your echo but the ‘wp’ will wait until, in this
   case, WP knows what page you are actually on.

Viewing 1 replies (of 1 total)

The topic ‘Conditional google analytics tag’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [tugbucket](https://wordpress.org/support/users/tugbucket/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/conditional-google-analytics-tag/#post-14753950)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
