I'm developing a Backdrop CMS website with Ubercart. It is necessary to place code for Google tag and event snippet on the conversion page in order to to link this website to Google ads system.

Placing the Google tag seems easy to me - by editing <head></head> section in template page.tpl.php in theme's template folder. This I guess should put the code on all pages on the site.

However, the code for the snippet on the conversion page should only be available on the completed order page:

cart/checkout/complete

I considered the possibility of doing this with a separate layout for
cart/checkout/complete

but the code in a given layout is only what is between <body> and </body> while the snippet on the conversion page should be put in the <head></head> section of the page, and it is managed by template page .tpl.php and it seems is the same for all layouts.

Is it possible to make a custom page.tpl.php which template is only active for cart/checkout/complete page?

Or in some other way to add event snippet code in <head></head> section only on the conversion page?

Thanks in advance for any idea or direction to solve this task.

Comments

I haven't tested this (never done that before), but have you tried implementing (or adding code to) your theme's implementation of hook_preprocess_page() (which is called before the page.tpl.php is used)?

In that implementation (e.g. in a function MY_THEME_preprocess_page() in your theme's template.php file) check for either the right path or other information to tell you that this is the correct page (for example checking current_path()) and then using backdrop_add_html_head() to add stuff to the head.

Again, untested!!!, but I think this is the way to go. preprocess functions are great opportunities to do things before a page is shown. According to the documentation of backdrop_add_html_head(), this is the last opportunity you have to add things to the head before the headers are sent to the browser.