PHP code example of growingio / php-sdk

1. Go to this page and download the library: Download growingio/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

growingio / php-sdk example snippets



use com\growingio\GrowingIO;
//Load Composer's autoloader


use com\growingio\GrowingIO;


$accountID = '1234567887654321';
$host = 'https://localhost.com';
$dataSourceId = '12345678';
$props = array('debug' => true);

$gio = GrowingIO::getInstance($accountID, $host, $dataSourceId, $props);

$gio->trackCustomEvent($gio->getCustomEventFactory()
    ->setEventKey('event_name')
    ->setLoginUserId('loginUserId')
    ->setAnonymousId('anonymousId')
    ->setEventTime(1648524854000)
    ->setLoginUserKey('loginUserKey')
    ->setProperties(array('attrKey1' => 'attrValue1',
        'attrKey2' => 'attrValue2',
        'array' => array('1', '2', '3')))
    ->create()
);

$gio->setUserAttributesEvent($gio->getUserAttributesFactory('loginUserId')
    ->setLoginUserId('loginUserId')
    ->setAnonymousId('anonymousId')
    ->setProperties(array('gender' => 'male',
        'age' => '18',
        'goods' => array('book', 'bag', 'lipstick')))
    ->setLoginUserKey('loginUserKey')
    ->create());

$gio->setItemAttributes(
    '1001',
    'product',
    array('color' => 'red')
);


use com\growingio\GrowingIO;

修改为您的项目AccountID
// 所有自定义事件需要提前在GrowingIO产品中进行定义
// 所有自定义事件的属性也需要提前在GrowingIO产品中进行定义
$accountID = '1234567887654321';
$host = 'https://localhost.com';
$dataSourceId = '12345678';
$props = array('debug' => true);
$gio = GrowingIO::getInstance($accountID, $host, $dataSourceId, $props);

// 采集自定义事件
$gio->trackCustomEvent($gio->getCustomEventFactory()
    ->setEventKey('event_name')
    ->setLoginUserId('loginUserId')
    ->setAnonymousId('anonymousId')
    ->setEventTime(1648524854000)
    ->setLoginUserKey('loginUserKey')
    ->setProperties(array('attrKey1' => 'attrValue1',
        'attrKey2' => 'attrValue2',
        'array' => array('1', '2', '3')))
    ->create()
);

// 设置登录用户变量
$gio->setUserAttributesEvent($gio->getUserAttributesFactory('loginUserId')
    ->setLoginUserId('loginUserId')
    ->setAnonymousId('anonymousId')
    ->setProperties(array('gender' => 'male',
        'age' => '18',
        'goods' => array('book', 'bag', 'lipstick')))
    ->setLoginUserKey('loginUserKey')
    ->create());

// 设置物品模型
$gio->setItemAttributes(
    '1001',
    'product',
    array('color' => 'red')
);
composer
"growingio/php-sdk": "1.0.3"