Post by tom327 » Wed Aug 18, 2021 7:45 am

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?

Active Member

Posts

Joined
Thu Feb 16, 2012 7:33 am

Post by straightlight » Wed Aug 18, 2021 7:54 am


Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by tom327 » 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.

Active Member

Posts

Joined
Thu Feb 16, 2012 7:33 am

Post by tom327 » Thu Aug 19, 2021 4:42 am

this extension seems very popular, and mentioed pixel, but not much details.
https://www.opencart.com/index.php?rout ... load_id=59

Active Member

Posts

Joined
Thu Feb 16, 2012 7:33 am

Post by straightlight » Thu Aug 19, 2021 7:23 am

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 78 guests