farmatholin/segment-io-bundle php lib

dev-master 2018-02-21 10:45 UTC


Bundle include library for analytics

include segmentio/analytics-php


The bulk of the documentation is stored in the Resources/doc folder in this bundle


Installing the bundle via packagist is the quickest and simplest method of installing the bundle. Here are the steps:

Step 1: Composer require

$ php composer.phar require "farmatholin/segment-io-bundle":"dev-master"

Step 2: Enable the bundle in the kernel

// app/AppKernel.php

public function registerBundles()
    $bundles = array(
        // ...
        new Farmatholin\SegmentIoBundle\SegmentIoBundle(),
        // ...

That's it! You are ready to use with symfony2.


Required segment write key:

# SegmentIoBundle Configuration
# app/config/config.yml
            write_key: "%your_key%" #add your key
            guest_id: "guest" # default guest. Guest id for annotation Track and Page
            env: prod #default prod. Can be prod (sending to segment) and dev (not sending)
                consumer: socket #default
                debug: false #default
                ssl: false #default
                max_queue_size: 10000 #default
                batch_size: 100 #default
                timeout: 0.5 #default
                filename: null #default


Get service from the service container and start using it:

$analytics = $this->get('');

Or using Annotations (Page and Track)

User for annotations is getting from TokenStorage. If user doesn't exit, id set to guest or from configuration 'guest_id'

use Farmatholin\SegmentIoBundle\Configuration\Page;
use Farmatholin\SegmentIoBundle\Configuration\Track;

     * @Route("/", name="homepage")
     * @Page(
     *     name="index",
     *     category="page",
     *     properties={"foo":"bar"}
     * )
     * @Track(
     *     event="visit homepage",
     *     properties={"bar":"foo"},
     *     useTimestamp=true,
     *     context={"aa":"bb"}
     * )
    public function indexAction(Request $request)
        // your code

Refer to analytics-php library.