How to trigger user flow when form submitted?

How to trigger user flow when form submitted?

Example: when form is submitted it should trigger values like user flow inside the contact form. How to pull out from Piwik Analytics such values?

Hi @gd83caw1gd

Users Flow report is based either on Page URL (default) or Page Title (can be selected below Source).

-> Therefore to see your “Form submitted” event in the Users flow report, you need to trigger a pageview (using javascript function trackPageView) when your form is submitted. For example you would call:


        _paq.push(['setCustomUrl', '/form-xyz-submitted']);
        _paq.push(['setDocumentTitle', 'Submitted form xyz']);
        _paq.push(['trackPageView']);

Please try this and let us know if this works for you or if you have any question.

Thanks,

So the whole code is like:

<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//{$PIWIK_URL}/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', {$IDSITE}]);

      **_paq.push(['setCustomUrl', '/contact-form-confirmation.html']);**
**      _paq.push(['setDocumentTitle', 'Confirmation | MyID | MyID |']);**
**      _paq.push(['trackPageView']);**

    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Piwik Code -->

  1. Is this the correct one?
  2. I have cookie name like cookie_myname
    How to add such names in the correct way inside the tracking code to follow also inside Piwik analytics?

You need to move these lines above the _paq.push(['trackPageView']); line in the code, in your “confirmation” page. (and remove the ** characters)

Thank you for very fast feedback and support.

  1. What about my cookie ID?
  2. What is actually definition for setCustomUrl? I mean there is HTTPS, en-GB folder. Can be included or this is pure last page file name even without HTML extension?

I don’t understand the question, could you explain in more details what you want to achieve?

We recommend to set only the URL path for example /dir1/dir2/page.html
-> Please try this and let us know if you have any question or feedback?

Each visitor is tracked by cookie ID.
It means we set cookie ID like myvalue_ID and we have its value. Simple as that.
How to put cookie name into PIWIK as it is created by each website.

Maybe I was not clear. Sorry.Cookie name and its value should be seen inside PIWIK statistics when I click on user flow. If we integrate PIWIK tracking code and our cookie name and its value it will be seen inside PIWIK Dashboard or not possible.

To track a “user ID” in Piwik you want to use User ID feature: User ID - Analytics Platform - Piwik

(However you won’t see the user id value in the Users Flow report. For this you’d need to track a “Custom pageview” or “Custom page title” and set the cookie value in there. But we don’t recommend to do that, as the Users Flow and other reports will become “useless” as each pageview will likely have a different name.)

If you use User ID then you can use Segmentation to view the Users Flow for a particular User ID: Segmentation - Compare segments of visitors - Analytics Platform - Piwik

So, this is the final code to be tracked as cookie name is not enough as user ID is not the name of cookie but cookies have values.

  var _paq = _paq || [];
  _paq.push(['setUserId', 'cookie_myname']);
  _paq.push(['setCustomUrl', '/en-GB/contact-form-confirmation.html']);
  _paq.push(['setDocumentTitle', 'Confirmation | MyID | MyID |']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//{$PIWIK_URL}/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', {$IDSITE}]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();


Can you confirm if this is the correct one?

This will always set your User ID to cookie_myname.
So likely this code is not correct. Instead likely you want to read the cookie value in javascript (for example) and pass the value inside the cookie to setUserId?

Otherwise the rest of the code looks good.

Is this the correct?
I have Javascript tracking code and the following line where should be placed cookie value and not its name:
_paq.push([‘setUserId’, ‘key=value’]);

If I place document.cookie = “key=value”; at the top of Javascript it should read value key=value.

This should work as long as key=value is actually read from the cookie. For this you need to have a function to read the value from the cookie, see for example What is the shortest function for reading a cookie by name in JavaScript? - Stack Overflow

I have tested and cookie is detected without any issue and seen also inside Piwik.
Is this actually conflict as I put both options:


        _paq.push(['setCustomUrl', '/form-xyz-submitted']);
        _paq.push(['setDocumentTitle', 'Submitted form xyz']);

If I track user flow when form is submitted is this also double conflict as trigger should be only one. Example URL or we need both to be seen inside Piwik Analytics?

It is best practise to put the two lines as you did there. It is not a conflict. Thanks,

How to to create report and send those values into email report?
How I can do this with the steps and send user flow per email reports as they can be created.

When you create a Custom Report, you can then add it to your Email reports by editing your Email report, and selecting the Custom Report you want to add to the report.

However Users Flow is not currently available in email reports. You can however email the table reports showing “Users Flow - Top Paths - Page URLs”, and “Users Flow - Overview - Page URLs” for either URL or Page title.

This feature is very important. When will be available?

you mean manually take snap image and send via email?