• France
Search
Categories
Tags
English
French
English
Implementation
Embedded form (cards)
REST payment API
Hosted payment
Push mail
File exchange
Mobile payment
Logos
Plugins
Back office
Guides
Helpers
FAQ
Support

Google Analytics

Google Analytics allows to monitor the traffic on each page of a website. It also allows to track the user’s actions on the page.

This article explains how to use the Google Analytics events with the embedded form and the pop-in.

In order to understand this article, you must have a basic understanding of the functioning of Google Analytics. For more information, go to the following page.

A Google Analytics event can be emitted in two ways:

Via the “browser return” page

At the end of the payment, the embedded form redirects the buyer to the payment confirmation page, also called the “browser return”. This URL is defined via the kr-post-url-success parameter:

https://github.com/lyra/rest-php-examples/blob/master/www/minimalEmbeddedForm.php#L81-L82
  <!-- Javascript library. Should be loaded in head section -->
  <script 
   src="https://static.systempay.fr/static/js/krypton-client/V4.0/stable/kr-payment-form.min.js" 
   kr-public-key="73239078:testpublickey_Zr3fXIKKx0mLY9YNBQEan42ano2QsdrLuyb2W54QWmUJQ" 
   kr-post-url-success="paid.html">
  </script>
  <!-- Javascript library. Should be loaded in head section -->
  <script 
   src="<?php echo $client->getClientEndpoint();?>/static/js/krypton-client/V4.0/stable/kr-payment-form.min.js"
   kr-public-key="<?php echo $client->getPublicKey();?>"
   kr-post-url-success="paid.php">
  </script>

For more information, go to: Getting started: single payment.

Cette page reçoit (dans les paramètres POST) la transaction nouvellement créée. Pour plus de détails, consultez la page Analyse du résultat du paiement via le retour navigateur. À partir de cette information, vous pouvez émettre un événement de la façon suivante:

<?php
require_once __DIR__ . '/vendor/autoload.php';
$client = new Lyra\Client();
$formAnswer = $client->getParsedFormAnswer();
?>
<script type="text/javascript">
ga('send', 'event', 'payment', 'new_transaction', 'status', "<?php echo $formAnswer['kr-answer']['orderStatus']; ?>");</script>

This example emits a new_transaction event in the payment category. The transaction status is also sent.

This example uses our PHP SDK. For more information, go to: Server SDKs.

Via the form page

If your website is of single page application type, you must emit the Google Analytics events in JavaScript. For this, use the events of the embedded form.

In order to retrieve the newly created transaction, you must use the KR.onSubmit event.

Example of code using jQuery:

<script type="text/javascript">
    $(document).ready(function(){
      KR.onSubmit( function(event){
        /* emit a Google Analytics event */
        ga('send', 'event', 'payment', 'new_transaction', 'status', event.clientAnswer.orderStatus));
        
        /* return values:
         * true: kr-post-success-url is called using POST
         * false: kr-post-success-url is not called, execution stops.
         */
        return false;
      });
    });
</script>

For more information on JavaScript events, go to: JavaScript client reference.

© 2023 | All rights reserved to Systempay | legal
2.24.0-doc-1.8