Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1327370

    gillawatts
    Participant

    I would like to add a Google Adwords tracking code to the “thank you” or “order received” page of my website in order to track conversions. I created a child theme, but I cannot seem to find where the thank you page is located. Do I need to build a thank you page from scratch and redirect woocommerce to it?

    http://www.gillawatts.com
    Wordpress 4.7.1
    Theme X 4.6.4
    Cornerstone 1.3.3

    Thank you

    #1327556

    Darshana
    Moderator

    Hi there,

    You can follow the example below.

    
    function my_custom_tracking_code() {
      if( is_page(185) ) {?>
        <!--replace this line with your tracking this -->
    <?php
      }
    }
    add_action('wp_head','my_custom_tracking_code');
    

    To locate page/post IDs, please refer to the following post (https://community.theme.co/kb/how-to-locate-post-ids/).

    Hope that helps.

    #1327714

    gillawatts
    Participant

    Thank you for your response, but I don’t think that I follow. The page you linked to does not give any instruction on how to locate page IDs, it is only for post IDs. I need to locate the “thank-you” or “order-received” page. Would this be located somewhere in the theme folder of my file directory or in the general woocommerce folder?

    Also, when using the code that you provided, would I change the line

    if( is_page(185) ) {?>

    to

    if( is_page(my page number here) ) {?>

    Or do I keep it at page 185?

    Thank you.

    #1327938

    Friech
    Moderator

    Hi There,

    You need to replace the (185) with the actual page ID, if you have the custom thank you page you can view the ID of it the same way as how you can view the posts ID on the URL.

    No, you don’t need to locate the files that output those pages. You just need the page ID.

    Actually you can locate the ID of any page by looking to its source-code. Please go to your thank-you page or order-received page. Press Ctrl + u (windows) or option + command + U (mac). Then Ctrl + f and find the string page-id- you should see a digit next to that, that is the page/post ID.

    Hope it helps, Cheers!

    #1329163

    gillawatts
    Participant

    Okay, I was able to locate the page ID of the order-received page. Where do I place the code snippet that you provided?

    Thank you

    #1329289

    Darshana
    Moderator

    Hi there,

    Please setup a child theme first, if you don’t have a child theme setup and activated already (https://community.theme.co/kb/how-to-setup-child-themes/).

    Then you can place the provided code into your child theme’s functions.php file.

    Thanks!

    #1343457

    gillawatts
    Participant

    Thank you. I was able to successfully create a child theme and add the provided code to the functions.php file with the proper page number written in.

    Google is able to recognize the code.
    However, I am testing the code with Google Tag Assistant, and I am getting two errors:

    “Code outside of body tags”

    Since I am adding this code to the functions.php file as opposed to the page itself, is there a way to direct the code to be read as if it is in the body section of that page?

    “Missing HTTP response”

    This might have more to do with editing the actual Adwords Conversion Tracking code, as Google only suggests to delete the code and reinstall it, but if you have any further insight as to what could be causing this error, please let me know.

    Thank you again for your assistance.

    #1343596

    Jade
    Moderator

    Hi there,

    Please update this line of code in the functions.php file:

    add_action('wp_head','my_custom_tracking_code');

    to

    add_action('x_before_site_begin','my_custom_tracking_code');

    Hope this helps.