2017 © Pedro Peláez
 

symfony-bundle lander-tracking-house-bundle

This bundle manages query tracking parameters.

image

exs/lander-tracking-house-bundle

This bundle manages query tracking parameters.

  • Monday, January 29, 2018
  • by rumpranger
  • Repository
  • 6 Watchers
  • 0 Stars
  • 1,204 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

EXS-LanderTrackingHouseBundle

Build Status, (*1)

What is this bundle doing ?

This bundle searches for tracking parameters in the request., (*2)

Stores the tracking parameters in cookies., (*3)

And then add those tracking parameters to any url using Formatter services., (*4)

Installation

Download the bundle using composer, (*5)

$ composer require exs/lander-tracking-house-bundle

Enable the bundle, (*6)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new EXS\LanderTrackingHouseBundle\EXSLanderTrackingHouseBundle(),
        // ...
    );
}

Configuration

The cmp, exid and visit parameters have a default value configurable with those configuration keys :, (*7)

# Default values.
exs_lander_tracking_house:
    default_cmp: ~
    default_exid: 'exid'
    default_visit: 1

Usage

Use the appendTracking Twig filter on any url.

If the user have got the required tracking parameters, the tracking parameters will be added., (*8)

Use a specific formatter

<a href="{{ 'https://www.foo.tld/bar' | appendTracking('foo') }}" target="_blank">Some link</a>

<a href="{{ url('homepage') | appendTracking('foo') }}" target="_blank">Some link</a>

Replace placeholders

<a href="{{ url('homepage', {'cmp': '{cmp}', 'exid': '{exid}'}) | appendTracking }}" target="_blank">Some link</a>

<a href="{{ 'https://www.foo.tld/bar?cmp={cmp}&exid={exid}&visit={visit}' | appendTracking }}" target="_blank">Some link</a>

Use getTracking('parameterName') Twig function to get any tracking parameter.

    <input type="hidden" name="foo" value="{{ getTracking('foo') }}">

Builtin extractor

  • cmp searches for the parameter named cmp in the request or the cookies. This parameter contains the cmp's value and is extracted as internal parameter cmp. If not found it will define a default value using exs_lander_tracking_house.default_cmp configuration's parameter.
  • cup searches for the parameter named cup in the request. This parameter contains a string composed of {cmp}~{exid}~{product_id} and is extracted as internal parameters cmp, exid and product_id.
  • cu searches for the parameter named cu in the request. This parameter contains a string composed of {cmp}~{exid} and is extracted as internal parameters cmp and exid.
  • cuvp searches for the parameter named cuvp in the request. This parameter contains a string composed of {cmp}~{exid}~{visit}~{product_id} and is extracted as internal parameters cmp, exid, visit and product_id.
  • cuv searches for the parameter named cuv in the request. This parameter contains a string composed of {cmp}~{exid}~{visit} and is extracted as internal parameters cmp, exid and visit.
  • exid searches for the parameter named exid or u or uuid in the request or cookies (Will use the first match). This parameter contains the exid's value and is extracted as internal parameters exid. If not found it will define a default value using exs_lander_tracking_house.default_exid configuration's parameter.
  • product_id searches for the parameter named p in the request. This parameter contains the product_id's value and is extracted as internal parameters product_id.
  • uvp searches for the parameter named uvp in the request. This parameter contains a string composed of {exid}~{visit}~{product_id} and is extracted as internal parameters exid, visit and product_id.
  • uv searches for the parameter named uv in the request. This parameter contains a string composed of {exid}~{visit} and is extracted as internal parameters exid and visit.
  • visit searches for the parameter named visit in the request or cookies. This parameter contains the visit's value and is extracted as internal parameters visit. If not found it will define a default value using exs_lander_tracking_house.default_visit configuration's parameter.

Builtin formatter

  • cup will use cmp, exid and product_id internal parameters to append the parameter cup composed of {cmp}~{exid}~{product_id}.
  • cu will use cmp and exid internal parameters to append the parameter cu composed of {cmp}~{exid}.
  • cuvp will use cmp, exid, visit and product_id internal parameters to append the parameter cuvp composed of {cmp}~{exid}~{visit}~{product_id}.
  • cuv will use cmp, exid and visit internal parameters to append the parameter cuv composed of {cmp}~{exid}~{visit}.
  • uvp will use exid, visit and product_id internal parameters to append the parameter uvp composed of {exid}~{visit}~{product_id}.
  • uv will use exid and visit internal parameters to append the parameter uv composed of {exid}~{visit}.

Adding an extracter

The bundle uses extracter services to find and get tracking parameters from the request, the cookies and/or define default value., (*9)

Those services have to implement EXS\LanderTrackingHouseBundle\Service\TrackingParameterManager\TrackingParameterQueryExtracterInterface and/or EXS\LanderTrackingHouseBundle\Service\TrackingParameterManager\TrackingParameterCookieExtracterInterface and/or EXS\LanderTrackingHouseBundle\Service\TrackingParameterManager\TrackingParameterInitializerInterface., (*10)

All those methods have to return a key/value array of tracking parameters found that will be saved in cookies., (*11)

Example :

1. Creating the extractor class for a new parameter foo

<?php

namespace My\SomeBundle\Service;

use Symfony\Component\HttpFoundation\ParameterBag;
use EXS\LanderTrackingHouseBundle\Service\TrackingParameterManager\TrackingParameterCookieExtracterInterface;
use EXS\LanderTrackingHouseBundle\Service\TrackingParameterManager\TrackingParameterQueryExtracterInterface;
use EXS\LanderTrackingHouseBundle\Service\TrackingParameterManager\TrackingParameterInitializerInterface;

class FooExtracter implements TrackingParameterCookieExtracterInterface, TrackingParameterQueryExtracterInterface, TrackingParameterInitializerInterface
{
    public function extractFromQuery(ParameterBag $query)
    {
        $trackingParameters = [];

        if (null !== $foo = $query->get('foo')) {
            $trackingParameters['foo'] = $foo;
        }

        return $trackingParameters;
    }

    public function extractFromCookies(ParameterBag $cookies)
    {
        $trackingParameters = [];

        if (null !== $foo = $cookies->get('foo')) {
            $trackingParameters['foo'] = $foo;
        }

        return $trackingParameters;
    }

    public function initialize()
    {
        return [
            'foo' => 123,
        ];
    }
}

Important thing to notice here : All keys from the array returned by an extractFromQuery(), extractFromCookies() and initialise() will be stored as a cookie., (*12)

In the example ahead, a cookie named foo will be stored with the value found in query or in cookies or else will define the default value., (*13)

2. Declare the service with tag exs_tracking.parameter_extracter

services:
    exs_tracking.foo_extracter:
        class: 'My\SomeBundle\Service\FooExtracter'
        tags:
            - { name: 'exs_tracking.parameter_extracter' }

In case many extracters have an initialise() method defined, we can specify a priority to know which default value to use (Higher value wins)., (*14)

services:
    exs_tracking.foo_extracter:
        class: 'My\SomeBundle\Service\FooExtracter'
        tags:
            - { name: 'exs_tracking.parameter_extracter', priotiry: 100 }

Adding a formatter

The bundle uses formatter services to get the parameters to append to an url., (*15)

Those services have to implements EXS\LanderTrackingHouseBundle\Service\TrackingParameterManager\TrackingParameterFormatterInterface., (*16)

They have to implement a format() method that will receive a ParameterBag containing all found tracking parameters from the request., (*17)

And it will need to return a key/value array of all formatted parameters to append to the url., (*18)

Those services also have to be tagged as exs_tracking.parameter_formatter., (*19)

See EXS\LanderTrackingHouseBundle\Service\TrackingParameterManager\CmpTrackingParameterFormatter for an example of formatter., (*20)

By convention formatter service's name is exs_tracking.xxxsomethingxxx_formatter., (*21)

Example :

1. Create the formatter class that implements EXS\LanderTrackingHouseBundle\Service\TrackingParameterManager\TrackingParameterFormatterInterface

<?php

namespace My\SomeBundle\Service;

use Symfony\Component\HttpFoundation\ParameterBag;
use EXS\LanderTrackingHouseBundle\Service\TrackingParameterManager\TrackingParameterFormatterInterface;

class FooFormatter implements TrackingParameterFormatterInterface
{
    public function format(ParameterBag $trackingParameters)
    {
        return [
            'foo' => $trackingParameters->get('foo'),
        ];
    }
}

2. Declare the service with tag exs_tracking.parameter_formatter

services:
    exs_tracking.foo_formatter:
        class: 'My\SomeBundle\Service\FooFormatter'
        tags:
            - { name: 'exs_tracking.parameter_formatter' }

3. Usage

As seen before, je just now need to use the Twig filter appendParameter on any url and the foo parameter will be added if defined., (*22)

    <a href="{{ 'http://www.test.tld/' | appendParameter('foo') }}">Some link</a>
    <!-- or -->
    <a href="{{ 'http://www.test.tld/?foo={foo}' | appendParameter}}">Some link</a>

The Versions

29/01 2018

dev-master

9999999-dev https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

29/01 2018

v1.1.7

1.1.7.0 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

29/01 2018

dev-CAMS-869

dev-CAMS-869 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

01/11 2017

v1.1.6

1.1.6.0 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

22/09 2017

v1.1.5

1.1.5.0 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

22/09 2017

v1.1.4

1.1.4.0 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

22/09 2017

v1.1.3

1.1.3.0 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

21/09 2017

v1.1.2

1.1.2.0 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

21/09 2017

v1.1.1

1.1.1.0 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

20/09 2017

v1.1.0

1.1.0.0 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

18/09 2017

v1.0.1

1.0.1.0 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter

14/09 2017

v1.0.0

1.0.0.0 https://github.com/ExSituMarketing/EXS-LanderTrackingHouseBundle

This bundle manages query tracking parameters.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ex-Situ Marketing

symfony2 bundle tracking parameter