escopecz / mautic-form-submit

PHP library to forward data to a Mautic form
MIT License
57 stars 14 forks source link

The submitted form data is not bound to the current contact by the mtc_id cookie #13

Open directpromo opened 5 years ago

directpromo commented 5 years ago

Hi @escopecz

Please help me...

There is a tracking domain domain.com and a separate domain where mautic is installed . From the tracking domain I send the my form via ajax to your script.

The matic form always creates a new contact with a contact id different from the current mtc_id cookie value in the browser.

Trying to take the current cookie under tracking domain via javascript: MauticJS.getTrackedContact()

So I get a cookie under the tracking domain: mtc_id, mtc_sid, magic_device_id

And then pass them to the mautic form via: curl_setopt($ch, CURLOPT_COOKIE, 'mtc_id=270; mtc_sid=r4pl1u2vgsdfdcf09bdo; magic_device_id=r4pl1u2vgsdfdcf09bdo; matic_session_id=r4pl1u2vgsdfdcf09bdo;')

It doesn't work :(

Found the reason that it works if you pass additionally the current (correct) cookie value music_referer_id curl_setopt($ch, CURLOPT_COOKIE, 'mtc_id=27709; mtc_sid=r4pl1u2vgsdfdcf09bdo; magic_device_id=r4pl1u2vgsdfdcf09bdo; matic_referer_id=656565; mautic_session_id=r4pl1u2vgsdfdcf09bdo;');

Is it a script bug, a mautic bug or am I doing something wrong?

Maybe there is a way to get the value of matic_referer_id on the tracking domain if the mautic is located on a separate domain?

zaharovrd commented 3 years ago

UP. Also....

zaharovrd commented 11 months ago

Hi @escopecz

Please help me...

There is a tracking domain domain.com and a separate domain where mautic is installed . From the tracking domain I send the my form via ajax to your script.

The matic form always creates a new contact with a contact id different from the current mtc_id cookie value in the browser.

Trying to take the current cookie under tracking domain via javascript: MauticJS.getTrackedContact()

So I get a cookie under the tracking domain: mtc_id, mtc_sid, magic_device_id

And then pass them to the mautic form via: curl_setopt($ch, CURLOPT_COOKIE, 'mtc_id=270; mtc_sid=r4pl1u2vgsdfdcf09bdo; magic_device_id=r4pl1u2vgsdfdcf09bdo; matic_session_id=r4pl1u2vgsdfdcf09bdo;')

It doesn't work :(

Found the reason that it works if you pass additionally the current (correct) cookie value music_referer_id curl_setopt($ch, CURLOPT_COOKIE, 'mtc_id=27709; mtc_sid=r4pl1u2vgsdfdcf09bdo; magic_device_id=r4pl1u2vgsdfdcf09bdo; matic_referer_id=656565; mautic_session_id=r4pl1u2vgsdfdcf09bdo;');

Is it a script bug, a mautic bug or am I doing something wrong?

Maybe there is a way to get the value of matic_referer_id on the tracking domain if the mautic is located on a separate domain?

did you manage to solve it?

zaharovrd commented 7 months ago

hi i fix this bug

https://github.com/escopecz/mautic-form-submit/pull/20

tsukasa1989 commented 2 months ago

I have the same issue, and also the fix above does not work. It is using mtc_id=90 in the cookie and in the data. How to not create a new contact, but use contact id 90 instead of creating a new one?

array(4) {
  ["original_cookie"]=>
  array(7) {
    ["PHPSESSID"]=>
    string(26) "44jjp87kjc5fk6vcbka52vb21v"
    ["mtc_id"]=>
    string(2) "90"
    ["mautic_device_id"]=>
    string(23) "kccqr2arqo64ic3hhnlx7je"
    ["CookieConsent"]=>
    string(183) "{stamp:'1U1ncy/AwScP/kbpR901s/KceimvfxFarUmRL5PZO0qCv6fPO970Xg==',necessary:true,preferences:true,statistics:true,marketing:true,method:'explicit',ver:1,utc:1727268676436,region:'nl'}"
    ["_gcl_au"]=>
    string(24) "1.1.978639211.1727268675"
    ["_ga"]=>
    string(26) "GA1.1.500559502.1727268667"
    ["_ga_SCY9JH99BT"]=>
    string(38) "GS1.1.1727268667.1.1.1727270087.57.0.0"
  }
  ["new_cookie"]=>
  array(7) {
    ["PHPSESSID"]=>
    string(26) "44jjp87kjc5fk6vcbka52vb21v"
    ["mtc_id"]=>
    string(2) "90"
    ["mautic_device_id"]=>
    string(23) "kccqr2arqo64ic3hhnlx7je"
    ["CookieConsent"]=>
    string(183) "{stamp:'1U1ncy/AwScP/kbpR901s/KceimvfxFarUmRL5PZO0qCv6fPO970Xg==',necessary:true,preferences:true,statistics:true,marketing:true,method:'explicit',ver:1,utc:1727268676436,region:'nl'}"
    ["_gcl_au"]=>
    string(24) "1.1.978639211.1727268675"
    ["_ga"]=>
    string(26) "GA1.1.500559502.1727268667"
    ["_ga_SCY9JH99BT"]=>
    string(38) "GS1.1.1727268667.1.1.1727270087.57.0.0"
  }
  ["request"]=>
  array(4) {
    ["header"]=>
    array(2) {
      [0]=>
      string(30) "X-Forwarded-For: 172.71.102.89"
      [1]=>
      string(24) "Client-Ip: 172.71.102.89"
    }
    ["url"]=>
    string(43) "https://e.domain.com/form/submit?formId=1"
    ["data"]=>
    array(2) {
      ["mauticform"]=>
      array(3) {
        ["email"]=>
        string(18) "niels@domain.com"
        ["formId"]=>
        int(1)
        ["return"]=>
        string(0) ""
      }
      ["mtc_id"]=>
      int(90)
    }
    ["query"]=>
    string(101) "mauticform%5Bemail%5D=niels%40domain.com&mauticform%5BformId%5D=1&mauticform%5Breturn%5D=&mtc_id=90"
  }
  ["response"]=>
  array(3) {
    ["header"]=>
    string(641) "HTTP/2 302 
server: openresty
date: Wed, 25 Sep 2024 13:20:59 GMT
content-type: text/html; charset=UTF-8
x-powered-by: PHP/8.1.28
cache-control: max-age=0, must-revalidate, private
location: /form/message
expires: Wed, 25 Sep 2024 13:20:59 GMT
set-cookie: mautic_device_id=oiwpj7zzmmuryexrproy2yz; expires=Thu, 25-Sep-2025 13:20:59 GMT; Max-Age=31536000; path=/; secure; samesite=none
set-cookie: mtc_id=107; path=/; secure; samesite=none
set-cookie: 5ec23ac4c72f90b7cdda01933796c7c3=4b7dba369396da194abf2473926bd517; path=/; httponly; samesite=lax
strict-transport-security: max-age=63072000; preload
x-served-by: e.domain.com"
    ["content"]=>
    string(416) "<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='/form/message'" />

        <title>Redirecting to /form/message</title>
    </head>
    <body>
        Redirecting to <a href="/form/message">/form/message</a>.
    </body>
</html>"
    ["info"]=>
    array(37) {
      ["url"]=>
      string(43) "https://e.domain.com/form/submit?formId=1"
      ["content_type"]=>
      string(24) "text/html; charset=UTF-8"
      ["http_code"]=>
      int(302)
      ["header_size"]=>
      int(645)
      ["request_size"]=>
      int(200)
      ["filetime"]=>
      int(-1)
      ["ssl_verify_result"]=>
      int(0)
      ["redirect_count"]=>
      int(0)
      ["total_time"]=>
      float(0.32368)
      ["namelookup_time"]=>
      float(0.00125)
      ["connect_time"]=>
      float(0.001829)
      ["pretransfer_time"]=>
      float(0.042216)
      ["size_upload"]=>
      float(101)
      ["size_download"]=>
      float(298)
      ["speed_download"]=>
      float(922)
      ["speed_upload"]=>
      float(312)
      ["download_content_length"]=>
      float(-1)
      ["upload_content_length"]=>
      float(101)
      ["starttransfer_time"]=>
      float(0.042222)
      ["redirect_time"]=>
      float(0)
      ["redirect_url"]=>
      string(35) "https://e.domain.com/form/message"
      ["primary_ip"]=>
      string(13) "XX"
      ["certinfo"]=>
      array(0) {
      }
      ["primary_port"]=>
      int(443)
      ["local_ip"]=>
      string(13) "XXXX"
      ["local_port"]=>
      int(46192)
      ["http_version"]=>
      int(3)
      ["protocol"]=>
      int(2)
      ["ssl_verifyresult"]=>
      int(0)
      ["scheme"]=>
      string(5) "HTTPS"
      ["appconnect_time_us"]=>
      int(42078)
      ["connect_time_us"]=>
      int(1829)
      ["namelookup_time_us"]=>
      int(1250)
      ["pretransfer_time_us"]=>
      int(42216)
      ["redirect_time_us"]=>
      int(0)
      ["starttransfer_time_us"]=>
      int(42222)
      ["total_time_us"]=>
      int(323680)
    }
  }
}