-
AuthorPosts
-
September 26, 2019 at 1:02 am #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
September 26, 2019 at 10:42 am #1142186Hey 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,
VictoriaOctober 1, 2019 at 8:39 pm #1143921Thank 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.
October 5, 2019 at 2:52 pm #1145269Hi 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,
VictoriaOctober 22, 2019 at 5:01 pm #1150222How can I add Google code to the header of one page?
Thank you,
— JohnOctober 22, 2019 at 5:24 pm #1150224Hi,
Just as mentioned above, in your child-theme add it to header.php. Just before the closing head tag
Best regards,
Jordan ShannonOctober 22, 2019 at 5:53 pm #1150238What 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
October 22, 2019 at 6:11 pm #1150248Hi,
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 ShannonOctober 22, 2019 at 7:08 pm #1150267Please see Private Content
October 22, 2019 at 8:06 pm #1150275Hi,
Did you add to the end of functions.php?
Best regards,
Jordan ShannonOctober 22, 2019 at 10:58 pm #1150321Not 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,
— JohnOctober 22, 2019 at 11:12 pm #1150325Hi,
Try with php tags:
<?php if (is_page('My-Page')) { echo '<script> gtag(‘event’, ‘conversion’, {‘send_to’: ‘AW-XXXXXXXXX/YYYYYYYYYYYY’}); </script>'; } ?>
Best regards,
Jordan ShannonOctober 22, 2019 at 11:33 pm #1150330Okay, 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 fileThank you again,
— John
October 22, 2019 at 11:35 pm #1150332Hi,
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 ShannonOctober 22, 2019 at 11:59 pm #1150337Please the Private Content . . .
October 24, 2019 at 3:37 pm #1150927In reply to your question, please see the Private Content . . .
October 26, 2019 at 3:40 pm #1151365Hi,
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,
MikeOctober 30, 2019 at 5:55 pm #1152438Thank you for the fix. It works great.
— John
October 30, 2019 at 7:07 pm #1152478Hi envatojlc,
Glad we could help :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.