forked from meinfernbus/GoogleBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdwords.php
67 lines (59 loc) · 2.05 KB
/
Adwords.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace AntiMattr\GoogleBundle;
use AntiMattr\GoogleBundle\Adwords\Conversion;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Adwords
{
const CONVERSION_KEY = 'google_adwords/conversion';
const CONVERSION_VALUE = 'google_adwords/conversion_value';
private $activeConversion;
private $container;
private $conversions;
public function __construct(ContainerInterface $container, array $conversions = array())
{
$this->container = $container;
$this->conversions = $conversions;
}
/**
* @param string $key
* @param float $value
*/
public function activateConversionByKey($key, $value = null)
{
/** @var $session \Symfony\Component\HttpFoundation\Session */
$session = $this->container->get('session');
if (array_key_exists($key, $this->conversions)) {
$session->set(self::CONVERSION_KEY, $key);
if (!is_null($value)) {
$session->set(self::CONVERSION_VALUE, $value);
} else {
$session->remove(self::CONVERSION_VALUE);
}
}
}
/**
* @return Conversion $conversion
*/
public function getActiveConversion()
{
/** @var $session \Symfony\Component\HttpFoundation\Session */
$session = $this->container->get('session');
if ($this->hasActiveConversion()) {
$key = $session->get(self::CONVERSION_KEY);
$session->remove(self::CONVERSION_KEY);
$config = $this->conversions[$key];
if ($session->has(self::CONVERSION_VALUE)) {
$config['value'] = $session->get(self::CONVERSION_VALUE);
}
$this->activeConversion = new Conversion($config['id'], $config['label'], $config['value'], $config['remarketing']);
}
return $this->activeConversion;
}
/**
* @param boolean $hasActiveConversion
*/
public function hasActiveConversion()
{
return $this->container->get('session')->has(self::CONVERSION_KEY);
}
}