Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #1142069

    How can I assign the Google gtag script to the header of one single page?

    Here are Google’s directions: “Copy the snippet below and paste it in between the <head></head> tags of the page(s) you’d like to track, right after the global site tag”

    Here is their dummy example,

    <!– Event snippet for Submit Bible Questions Form conversion page –>
    <script>
    gtag(‘event’, ‘conversion’, {‘send_to’: ‘AW-XXXXXXXXXX/2yeCCNa2zoUBEPO6qvwC’});
    </script>

    Thank you

    #1142186

    Hey John,

    Please have a look at the following threads:
    https://kriesi.at/support/topic/enfold-child-theme-add-google-analytics-code/

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1143921

    Thank you for the links.

    Now I have another question. I saw the following code in the first link,

    function add_ga_code(){
    ?>
    YOUR Google Analytics CODE GOES HERE
    <?php
    }
    add_action(‘wp_head’, ‘add_ga_code’);

    This code example appears to place the Google Tag script between the header tags. But I need to place code between the body tags: <body></body>.

    I have placed the Google Tag instruction in the Private section. I hope clarifies what i am trying to accomplish (I replaced account numbers with XXXXXXX). Therefore, my question is, “How do I place Google tag code the first place between the body tags?

    Thank you for the help.

    #1145269

    Hi envatojlc,

    You can edit the enfold/header.php file and add the code there. You need to have the child theme and copy the header file there and make your changes there.

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1150222

    How can I add Google code to the header of one page?

    Thank you,
    — John

    #1150224

    Hi,

    Just as mentioned above, in your child-theme add it to header.php. Just before the closing head tag

    Best regards,
    Jordan Shannon

    #1150238

    What am I missing? If I add the Google code to header.php then it will exist on every page on the site.

    Google Adwords wants a specific piece of tracking code embedded on a “thank you page” that I have on the site. How do I apply tracking code to just one single page?

    — John

    #1150248

    Hi,

    You would need to use the following in functions.php:

    <?php if ( is_page( 'contact' )) {
        echo 'YOUR SCRIPT HERE';
    } ?>

    Replace the “contact” with your page slug.

    Best regards,
    Jordan Shannon

    #1150267

    Please see Private Content

    #1150275

    Hi,

    Did you add to the end of functions.php?

    Best regards,
    Jordan Shannon

    #1150321

    Not at first.

    Therefore, I moved it to the end of the functions.php file and received the following error warning,

    “Your PHP code changes were rolled back due to an error on line 550 of file wp-content/themes/enfold-child/functions.php. Please fix and try saving again.
    syntax error, unexpected ‘for’ (T_FOR)”

    Line 550 refers to the first line of the following code (I masked the page and then the numbers with Xs and Ys). What is wrong with the first line?

    if ( is_page( ‘My-Page’ )) {
    echo ‘
    <script>
    gtag(‘event’, ‘conversion’, {‘send_to’: ‘AW-XXXXXXXXX/YYYYYYYYYYYY’});
    </script>
    ‘;
    }

    Thank you again,
    — John

    #1150325

    Hi,

    Try with php tags:

    <?php if (is_page('My-Page')) 
    { 
    echo '<script>
    gtag(‘event’, ‘conversion’, {‘send_to’: ‘AW-XXXXXXXXX/YYYYYYYYYYYY’});
    </script>'; 
    } 
    ?>

    Best regards,
    Jordan Shannon

    #1150330

    Okay, I inserted the following code (after inserting the correct parameters for My-Paeg and the Xs and Ys),

    <?php if (is_page(‘My-Page’))
    {
    echo ‘<script>
    gtag(‘event’, ‘conversion’, {‘send_to’: ‘AW-XXXXXXXXX/YYYYYYYYYYYY’});
    </script>’;
    }
    ?>

    and receive the following error. Please note that the first line of the above code is 550.

    Your PHP code changes were rolled back due to an error on line 550 of file wp-content/themes/enfold-child/functions.php. Please fix and try saving again.
    syntax error, unexpected ‘<‘, expecting end of file

    Thank you again,

    — John

    #1150332

    Hi,

    Can you provide admin info in the private area so we can log in and look into this further. We can see what else in that functions file.

    Best regards,
    Jordan Shannon

    #1150337

    Please the Private Content . . .

    #1150927

    In reply to your question, please see the Private Content . . .

    #1151365

    Hi,
    Sorry for the late reply, and thanks for the login. I added this code to your functions.php and it is now working on the one page:

    function custom_script(){
      if ( is_page( '37145' ) ) { ?>
      <script>
      gtag('event', 'conversion', {'send_to': 'AW-yourID'});
      </script>
      <?php }
      }
      add_action('wp_footer', 'custom_script');

    naturally I used your posted AW-ID

    Best regards,
    Mike

    #1152438

    Thank you for the fix. It works great.

    — John

    #1152478

    Hi envatojlc,

    Glad we could help :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

Viewing 19 posts - 1 through 19 (of 19 total)
  • You must be logged in to reply to this topic.