Skip to content

Instantly share code, notes, and snippets.

@willwashburn
Last active June 15, 2017 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willwashburn/d864151cbeff30f04b99160fb95987d5 to your computer and use it in GitHub Desktop.
Save willwashburn/d864151cbeff30f04b99160fb95987d5 to your computer and use it in GitHub Desktop.
<?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' => 'will@tailwindapp.com',
'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