Last active
August 29, 2015 14:02
-
-
Save sergejmueller/d7cb47220cc3b3a6dbfd to your computer and use it in GitHub Desktop.
Tracking der Bestellungen in Google Analytics (GA) mithilfe von PHP und Measurement Protocol. Weitere Informationen: https://developers.google.com/analytics/devguides/collection/protocol/v1/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // GA Tracking ID | |
| $tid = 'UA-XXXXXXX-XX'; | |
| // Anonymous Client ID | |
| $cid = sprintf( | |
| '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', | |
| mt_rand( 0, 0xffff ), | |
| mt_rand( 0, 0xffff ), | |
| mt_rand( 0, 0xffff ), | |
| mt_rand( 0, 0x0fff ) | 0x4000, | |
| mt_rand( 0, 0x3fff ) | 0x8000, | |
| mt_rand( 0, 0xffff ), | |
| mt_rand( 0, 0xffff ), | |
| mt_rand( 0, 0xffff ) | |
| ); | |
| // Track order | |
| file_get_contents( | |
| sprintf( | |
| 'https://ssl.google-analytics.com/collect?payload_data&%s', | |
| http_build_query( | |
| array( | |
| 'v' => 1, | |
| 'tid' => $tid, | |
| 'cid' => $cid, | |
| 'cu' => 'EUR', | |
| 'tr' => $order_cost, | |
| 't' => 'transaction', | |
| 'ti' => $txn_id | |
| ) | |
| ) | |
| ) | |
| ); | |
| // Track item | |
| file_get_contents( | |
| sprintf( | |
| 'https://ssl.google-analytics.com/collect?payload_data&%s', | |
| http_build_query( | |
| array( | |
| 'v' => 1, | |
| 'tid' => $tid, | |
| 'cid' => $cid, | |
| 'cu' => 'EUR', | |
| 'in' => 'Product', | |
| 'ip' => $order_cost, | |
| 't' => 'item', | |
| 'iq' => 1, | |
| 'ti' => $txn_id | |
| ) | |
| ) | |
| ) | |
| ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
file_get_contents ist übersichtlicher, weil nur ein Befehl. Klar, kann man auch cURL nehmen.