digitalwithyou / craft-facebook-conversion

Craft CMS plugin to send web events directly to Facebook
https://digitalwithyou.com/en/plugins/facebook-conversion/getting-started
Other
0 stars 3 forks source link

Purchase event is not tracked #9

Open boldenamsterdam opened 3 years ago

boldenamsterdam commented 3 years ago

Hi @Diewy

We are facing an issue with the default event Purchase in our Commerce 3 shop. Currently we are running the plugin with a test_event configured, since we are in the process of replacing the current JS implementation.

We do see the default AddToCart event and a custom event we added our selfs ViewContent in the FB events test manager.

We tried to find the issue in the logs but can't find any traces in the logs. We searched for the curl request https://graph.facebook.com like was mentioned in the documentation -> logs but can't find anything. Also not the AddToCart and custom event ViewContent

If you need more info or have questions, please let us know.

Craft CMS: 3.6.17 Commerce: 3.3.4.1 PHP: 8.0.3

Diewy commented 3 years ago

Hi @boldenamsterdam,

Logs: Are you using a custom logger? And are other info logs shown in your log?

Purchase Event: While checking your issue I noticed a small improvement that could be made with the currencies, I released a new version for it. You might want to try that version since it seems to improve the events shown in the Test Events tab.

When that wouldn't work I suggest trying to fix the logging issue first, without the exact payload it is difficult to determine what is going wrong.

boldenamsterdam commented 3 years ago

Hi @Diewy

A short update from our side.

We tried to temp. fix it by adding the event manually to the template, but now we see the default event is fired and our manual event in the FB event manager. Also after removing our manual event it still works 🤔 Maybe there was not enough data, so FB didn't show it in the Event Manager?

But we still can't find any traces in the logs. If that could be fixed would be super helpful, so in the future it's easier to debug 🙂
We use the default logging, no custom and we do see other info being logged.

boldenamsterdam commented 3 years ago

PS: we will also try-out your latest fix! Thanks!

Diewy commented 3 years ago

Thanks for the update.

Craft::info is used to log the requests. Could you try adding \Craft::info('This is a test'); to the end of your web/index.php file and check if "This is a test" is logged?

When it is not logged, there something wrong with the logs of your Craft CMS setup.

When it is is logged, could you add var_dump($eventRequest);exit; to line 57 of /vendor/dwy/facebook-conversion/src/services/FacebookBusinessApi.php in a test environment? Does it show the data when adding something to your cart?

It would be useful to compare the dump of the AddToCart and Purchase event and find any differences.

karensg commented 3 years ago

Hi @Diewy,

I took over the development from @boldenamsterdam. It is about the same website. So this happens: We are using Mollie as a payment provider. The event is sent to Facebook, but Facebook does not accept it as (1)ip address, (2) browser and (3) user agent are different. Also AddToCart does not have the external_id at all, which is weird while it is present for ViewCart frontend event.

There are two directions where we can go:

  1. Add an option in the plugin to disable automatic send and add a twig method to call it for an order. Every developer can then add it success.twig. Seems to me as the easiest option, but not all events will be passed as the user will not always return. EG bank transfer method.
  2. Try to make sure that we match the user data in the webhook event. IP address is eg already in Craft already. Easy fix. fbp should then be stored separately.

Let me know what your thoughts are.

K

PS, Craft:info only ends up in web.log when DEV_MODE is on.

karensg commented 3 years ago

UPDATE: digged in a bit more.

While that is an issue, I think the problem might not be that. Tried to curl the request and get {"events_received":1,"messages":[],"fbtrace_id":"Au97H60Cdt-GZIv-R3EAFOP"} However, the event never shows up, also not with test mode. Some other events do actually pass through even if I send them second time.

I wonder whether we should add a fronted implementation for the same event with the Facebook pixel. In that case we would need to use the event_id parameter so that Facebook is able to dedupe them.

I also think it is a good idea to:

Event which is not working

[
  {
    "event_name": "Purchase",
    "event_time": 1629125711,
    "event_source_url": "https:\/\/client.com\/index.php?p=actions\/commerce\/webhooks\/process-webhook&gateway=2&commerceTransactionHash=bde9a35e3eddfd92b136bac807d40785",
    "user_data": {
      "em": [
        "<REMOVED>"
      ],
      "ph": [
        ""
      ],
      "ln": [
        "<REMOVED>"
      ],
      "fn": [
        "<REMOVED>"
      ],
      "ct": [
        "<REMOVED>"
      ],
      "zp": [
        "<REMOVED>"
      ],
      "country": [
        "<REMOVED>"
      ],
      "external_id": [
        "$2y$13$CFZ2s0Oov7S6QpenW4DBBe\/zM5c2dAW9HugfT4tro.5I0bAtukz.y"
      ],
      "client_ip_address": "87.233.217.247",
      "client_user_agent": "Mollie HTTP client\/1.0",
      "fbp": "fb.1.1629125710.6091481414"
    },
    "custom_data": {
      "value": 144.9,
      "currency": "eur",
      "content_type": "product",
      "contents": [
        {
          "id": "74210354391",
          "quantity": 2,
          "item_price": 69.95
        }
      ]
    },
    "action_source": "website"
  }
]
karensg commented 3 years ago

@Diewy, any thoughts?

Diewy commented 3 years ago

Hi @karensg, I'll take a look over the weekend and come back to you.

Diewy commented 3 years ago

Hi @karensg ,

Let me first verify that Craft Commerce is used with the Mollie payment gateway (not to be confused with the Mollie Payments Plugin), correct?

I couldn't replicate the issue, both Add to cart and Purchase event were working as expected with the payment gateway during testing. But, I do agree with some of your remarks. I published a new version with the following updates as suggested:

Does the Purchase event now work for you? I noticed that in the event your shared no test event code is sent, could you also check that?

karensg commented 3 years ago

Hi @Diewy, I appreciate that you are looking in to the issue. I am using the Mollie Payment Gateway indeed. I will install the update, test it in the coming days and let you know whether it solved the issue.

karensg commented 3 years ago

Hi @Diewy,

I have used the new version on production for a day now and here are my observations:

I would suggest that we also add event_id = order_id for purchase events. In this case, everybody can also send the frontend events manually without having fear that they will be tracked double in FB. I will do it on the frontend myself then. https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data#order-id

There are also some other issues that I have which might be related to the acceptance rate, but I will create new issue(s) for that to keep it clean.

karensg commented 3 years ago

HI @Diewy,

Unfortunately, the acceptance rate is below 40% again. I am not sure why Facebook is not accepting the events, but I will need to move back to complementary frontend events as the customer is not happy. Could you please implement the event_id functionality, so that plugin users can use this plugin with frontend events? That would be super helpful ❤️