facebook Conversion API integration
-
loop
- Contributor
- Posts: 253
- Joined: Thu Mar 25, 2021 12:26 pm
- Phoenix Version:
- Has thanked: 7 times
- Been thanked: 3 times
facebook Conversion API integration
hi All
i'm on a modul / hook for the facebook conversion API. in basic i need to make server curl request on different states, add to cart, successpage, view_products..
what is the best way to do this in a single place without editing to listen to "add_to_cart" and then make a serverside request and on checkout_success do it also...
is the best place a hook? what are the listening for add to cart? would really appriciate a hint / help
thanks!
i'm on a modul / hook for the facebook conversion API. in basic i need to make server curl request on different states, add to cart, successpage, view_products..
what is the best way to do this in a single place without editing to listen to "add_to_cart" and then make a serverside request and on checkout_success do it also...
is the best place a hook? what are the listening for add to cart? would really appriciate a hint / help
thanks!
-
loop
- Contributor
- Posts: 253
- Joined: Thu Mar 25, 2021 12:26 pm
- Phoenix Version:
- Has thanked: 7 times
- Been thanked: 3 times
Re: facebook Conversion API integration
i have made a hook ( i believe this is the way):
but my first problem is, that the class facebookConversionsApi is not loaded automaticly and i have to include it myself in the hook (don't know if that's a good idea?)
if you have any tips / better idea i would appriciate...i will try now to extend this hook for every event (Succes page, add to cart, view product....)
and the last thing i cannot get to work is i need a hook for add_to_cart (like the action module)
namespace Phoenix\Actions;
class add_product {
public static function execute() {
i want that as soon as add_product is done i can fire the event
Code: Select all
<?php
/*
$Id$
CE Phoenix, E-Commerce made Easy
https://phoenixcart.org
Copyright (c) 2021 Phoenix Cart
Released under the GNU General Public License
*/
include 'includes/classes/facebookConversionsApi.php';
class hook_shop_siteWide_facebookCapi {
public function listen_injectSiteStart() {
//pageview
$fb_api = new FacebookConversionsAPI();
$fb_api->sendEvent('ViewContent');
}
}if you have any tips / better idea i would appriciate...i will try now to extend this hook for every event (Succes page, add to cart, view product....)
and the last thing i cannot get to work is i need a hook for add_to_cart (like the action module)
namespace Phoenix\Actions;
class add_product {
public static function execute() {
i want that as soon as add_product is done i can fire the event
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: facebook Conversion API integration
Try renaming the file to facebook_conversions_a_p_i.php and see if it can find that.
If you are using the same variable multiple times, try
Code: Select all
$fb_api =& Guarantor::ensure_global('FacebookConversionsAPI');Code: Select all
protected $fb_api;
public function __construct() {
$this->fb_api = new FacebookConversionsAPI();
}Code: Select all
$this->fb_api->sendEvent('ViewContent');Listening to actions, like Add to Cart would need to be done in a system hook, as they happen before siteWide is started. https://github.com/CE-PhoenixCart/Phoen ... .sql#L1185
You need to listen for the event before that. E.g. hook_shop_system__16fb_actions (if you are using file hooks with a global variable). You might want to check that product_id is set before generating the event. You definitely should check $_GET['action'] before reporting any of those events.
-
loop
- Contributor
- Posts: 253
- Joined: Thu Mar 25, 2021 12:26 pm
- Phoenix Version:
- Has thanked: 7 times
- Been thanked: 3 times
Re: facebook Conversion API integration
hi ecartz
thank you!
most of your comment i already done, but that with listening to add_cart i don't know exactly how you mean this:
do i need to move my filebased hook to system? class hook_shop_siteWide_facebookCapi ? can i have my code still in the same file or do i need to have 1 hook in siteWide and one in system?
i'm not really familiar with db hooks, should i make 2 hooks like:
i'm not sure about hooks_action what this is exactly and what i have to set here
and thann delete my hook in sitewide and make a class facebookCapi.php ?
if possible and easier i like to switch to db hooks, but im not verry familiar with the database hooks and i don't know how to do it, thank you very much for your help
thank you!
most of your comment i already done, but that with listening to add_cart i don't know exactly how you mean this:
do i need to move my filebased hook to system? class hook_shop_siteWide_facebookCapi ? can i have my code still in the same file or do i need to have 1 hook in siteWide and one in system?
i'm not really familiar with db hooks, should i make 2 hooks like:
Code: Select all
INSERT INTO hooks (hooks_site, hooks_group, hooks_action, hooks_code, hooks_class, hooks_method) VALUES ('shop', 'system', 'startApplication', '_16fb_actions', 'facebookCapi', 'add_to_cart');
INSERT INTO hooks (hooks_site, hooks_group, hooks_action, hooks_code, hooks_class, hooks_method) VALUES ('shop', 'siteWide', 'SiteStart', '_16fb_actions', 'facebookCapi', 'SiteStart');
and thann delete my hook in sitewide and make a class facebookCapi.php ?
Code: Select all
class facebookCapi {
protected $fb_api;
public function __construct() {
$this->fb_api = new FacebookConversions_a_p_i();
}
public function add_to_cart() {
mail("myemail@email.ch", "add_product0", "yes");
}
public function SiteStart() {-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
-
loop
- Contributor
- Posts: 253
- Joined: Thu Mar 25, 2021 12:26 pm
- Phoenix Version:
- Has thanked: 7 times
- Been thanked: 3 times
Re: facebook Conversion API integration
hmm but something doesn't work
i have the 2 hooks inserted
and i have the class: includes/classes/facebookCapi.php
but nothing happends i don't receive a email or see a echo whenn i browse the test shop..so it seems something is wrong...any ideas?
i have the 2 hooks inserted
Code: Select all
INSERT INTO hooks (hooks_site, hooks_group, hooks_action, hooks_code, hooks_class, hooks_method) VALUES ('shop', 'system', 'startApplication', '_16fb_actions', 'facebookCapi', 'add_to_cart');
INSERT INTO hooks (hooks_site, hooks_group, hooks_action, hooks_code, hooks_class, hooks_method) VALUES ('shop', 'siteWide', 'SiteStart', '_16fb_actions', 'facebookCapi', 'SiteStart');
Code: Select all
class facebookCapi {
protected $fb_api;
public function __construct() {
$this->fb_api = new FacebookConversions_a_p_i();
}
public function add_to_cart() {
mail("xx@xx.ch", "add_product0", "yes");
echo "add_product0";
}
public function SiteStart() {
echo "SiteStart"; .....-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: facebook Conversion API integration
Perhaps change the action from SiteStart to siteWideStart
Check that you are adding to cart (what happens on the product info page) and not buying now (from product listings).
Check that you are adding to cart (what happens on the product info page) and not buying now (from product listings).