Last active
June 15, 2017 22:19
-
-
Save willwashburn/d864151cbeff30f04b99160fb95987d5 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// Include the segment library from https://github.com/segmentio/analytics-php | |
include 'path_to_segment.php'; | |
// Initialize with segment's defaults and simple error logging | |
Segment::init('WRITE_KEY_HERE', [ | |
"error_handler" => function ($code, $msg) { error_log("Segment error:$code $msg"); }, | |
]); | |
$event = 'test_event'; | |
/// Extra big parameters list | |
$parameters = []; | |
for($i=0;$i<300;$i++) { | |
$parameters[] = str_random(); | |
} | |
// Track 50 events | |
for($i=0;$i<50;$i++) { | |
$data = [ | |
'userId' => 1425, | |
'event' => $event, | |
'properties' => $parameters, | |
'timestamp' => time(), | |
'context' => [ | |
'active' => false, | |
'traits' => [ | |
'email' => '[email protected]', | |
'name' => 'Will Washburn', | |
'created_at' => 1371245335, | |
], | |
], | |
]; | |
Segment::track($data); | |
} | |
/* | |
* Generate a "random" alpha-numeric string. | |
* | |
* Should not be considered sufficient for cryptography, etc. | |
* | |
* @param int $length | |
* @return string | |
*/ | |
public static function str_random($length = 16) | |
{ | |
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
return substr(str_shuffle(str_repeat($pool, $length)), 0, $length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment