Page 1 of 1

How to add Facebook Pixel code to specific pages

Posted: Wed Aug 18, 2021 7:45 am
by tom327
I needed to add Facebook pixel code to my website.
I know how to add the code to the header.twig template.
But the problem is that I want to use one version of the Pixel code for my checkout success page and another version for all my other pages.

I think I need some kind of conditional that will check the page. In doing some research, my understanding is that I should be able to check a page's route to see if it is the checkout success page?
But, I was having a hard time working with the twig files.
I did one test like this below, to see if I could test for the about us page, but it did not work. Broke whole site.

Code: Select all

{% if $_GET['route'] is defined and $_GET['route'] == 'information/information&information_id=4' %}
    <!-- Facebook Pixel Code -->
	<!-- End Facebook Pixel Code -->
{% endif %}
Can anyone suggest a better way to do this?

Is is possible to check for the page's route, and use that in a conditional?
Is there some better way to add specific facebook pixel code to specific pages?

Re: How to add Facebook Pixel code to specific pages

Posted: Wed Aug 18, 2021 7:54 am
by straightlight

Re: How to add Facebook Pixel code to specific pages

Posted: Wed Aug 18, 2021 7:25 pm
by paulfeakins
OCMOD

Re: How to add Facebook Pixel code to specific pages

Posted: Thu Aug 19, 2021 4:32 am
by tom327
That information about using event system is beyond my skill level.
As pointed out, it is suggested I look at OCmod? I assume an extension? Is there one you would recommend? Or did you mean to create my own ocmod?

Though I was surprised it would be a common task to be able to conditionally add some code to the head element of some pages in the store, and I was hoping there was some standard way of doing that.

Re: How to add Facebook Pixel code to specific pages

Posted: Thu Aug 19, 2021 4:42 am
by tom327
this extension seems very popular, and mentioed pixel, but not much details.
https://www.opencart.com/index.php?rout ... load_id=59

Re: How to add Facebook Pixel code to specific pages

Posted: Thu Aug 19, 2021 7:23 am
by straightlight
tom327 wrote:
Thu Aug 19, 2021 4:32 am
That information about using event system is beyond my skill level.
As pointed out, it is suggested I look at OCmod? I assume an extension? Is there one you would recommend? Or did you mean to create my own ocmod?

Though I was surprised it would be a common task to be able to conditionally add some code to the head element of some pages in the store, and I was hoping there was some standard way of doing that.
Since OCMod is on the road of deprecation, using Events is the standard way of doing that without modifying core files.