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:
Depuis la page "retour à la boutique"
À la fin du paiement, le formulaire embarqué redirige l'acheteur sur la page de confirmation de paiement, aussi appellée "retour à la boutique". Cette URL est définie à partir du paramètre kr-post-url-success:
<!-- Javascript library. Should be loaded in head section --> <script src="https://static.osb.pf/static/js/krypton-client/V4.0/stable/kr-payment-form.min.js" kr-public-key="58739933:testpublickey_NUFA6m8QLqEaHktbQ1TkA7Z596H8KEFCiKOaO4871cZCH" 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 à la boutique. À 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.