- Posts: 303
- Thank you received: 18
Facebook Pixel Firing Twice for Paypal
- mojooutdoors-holden
-
Topic Author
- Offline
-- Joomla version -- : 3.8.5
I've added my Facebook Tracking pixel to the top of the "after_end" view. As you get redirected to Paypal, everything is fine. Normally, you would expect the pixel to fire once payment has been confirmed in paypal and after the redirection back to the thank you page (after_end view file). However, if you cancel the paypal payment and return to the payment window on my site, the pixel fires....even though the "after_end" file has not been called.
I've checked multiple times and the pixel is only on the "end" (for first data payment) and "after_end" (for PayPal). Any reason why canceling the PayPal payment would result in the "after_end" view file being called? Then, in the case where users canceled it and decided to pay with First Data, i see an instance where the pixel was fired twice for the same purchase. Obviously, this is showing false positives in my tracking statistics.
I should note that it's working properly for all confirmed orders, and seems to only be a problem on orders where customers cancel the payment and return to our website. The only reason I noticed this behavior is the Facebook conversion stats show I sold more than what I actually sold. The difference seems to be the canceled payment amount.
Please Log in or Create an account to join the conversation.
The after_end view file is only called after the paypal payment. It cannot be called before. I don't see how it would.
I presume that it must be the pixel code you've added in the "end" view file which is fired when it shouldn't because of the way you added it to it.
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
The only other question i have is how to prevent the pixel from firing again if you reload the thank you page???
Please Log in or Create an account to join the conversation.
Indeed, the way you had the code placed there meant that the pixel was also added for each paypal transaction since the paypal payment method also uses the "end" view before the redirection to add its form to it through the $this->html variable.
Placing it in the if is indeed a good solution.
To avoid your code running several times if the customer reload the page, you should set a variable in the user session and check against it.
Something like that:
Note also that since the view files of HikaShop are in HikaShop, HikaShop is already loaded.
So the code
Note also that the code:
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
Awesome support as always!
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
The reason I ask is that I tried two test orders 10 minutes apart and the second one didn't fire the pixel.
Please Log in or Create an account to join the conversation.
Sure. You can do like that for example:
Note that in Joomla, you don't need, and shouldn't create or destroy the PHP session. That's handled by Joomla automatically for you. You just want to set a timer in it to know how much time has passed since last order.
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
I believe the view file that displays after the credit card payment is processed is "checkout/end.php"
Currently I have the following:
Am i missing something obvious???
Please Log in or Create an account to join the conversation.
You're basing yourself on whether $this->html is empty or not to display the facebook pixel.
However, it's possible that some credit card payment plugins (which display the credit card form directly during the checkout) fill the $this->html variable with their own thank you page instead of HikaShop's default one.
So instead of basing yourself on that variable, it would be better to check whether $this->order->order_payment_method == 'paypal'
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
Also be better to put this as the head of the file or within the " if(empty($this->html)) " conditional???
Please Log in or Create an account to join the conversation.
You can even simplify your code and have:
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
or within the if statement further down like this:
**** ALSO, i noticed there isn't a closing php tag at the end of the default "after_end" file? Was this on purpose?
Please Log in or Create an account to join the conversation.
You should put it at the beginning yes.
Ideally, it's best to put it just after the code:
No closing PHP tag at the end is done on purpose.
If you happen to have extra characters after the last closing tag of a PHP file, these characters will end up in the output buffer of PHP. It might happen inadvertedly. And if you try to ouput headers after characters have been already ouput, it could generate errors and event break the downloads of files.
So it's better to never have closing PHP tags at the end of PHP files to avoid such risks. It's a good practice:
stackoverflow.com/questions/3219383/why-...-the-closing-php-tag
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
Therefore, I added it to the top of the "after_end" file. Seems to be firing properly for Paypal orders. Any reason why this would not work?
Please Log in or Create an account to join the conversation.
That's normal. You need to add the code to both end and after_end. If you only add it to end, it's normal that it would work for PayPal due to the way the system works.
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
However, i'm able to add it after this block in the "end" file.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
Thanks again!
Please Log in or Create an account to join the conversation.