Skip to content

Commit

Permalink
Initial commit of Bundle, including GA, GTM, Logrocket, Fullstory, & …
Browse files Browse the repository at this point in the history
…Hotjar support
  • Loading branch information
chrisaligent committed May 24, 2019
0 parents commit 9ae503d
Show file tree
Hide file tree
Showing 30 changed files with 1,111 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2019-present FriendsOfOro, Aligent Consulting, and other contributors

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Oro Customer Tracking Bundle
==============================
This bundle adds support for user tracking code injection.

Currently supported trackers are:
* [Google Analytics](https://analytics.google.com/analytics/web/)
* [Google Tag Manager (GTM)](https://tagmanager.google.com/)
* [LogRocket](https://logrocket.com/)
* [Hotjar](https://www.hotjar.com/)
* [Fullstory](https://www.fullstory.com/)

For applicable trackers, the currently logged-in user will also be provided with the tracking payload.

NOTE: [Google Analytics Ecommerce Tracking](https://support.google.com/analytics/answer/1009612?hl=en) **is not currently supported**

Inspired by the [OroCommerce Analytics/GTM Bundle](https://github.com/DivanteLtd/orocommerce-ga) by DivanteLtd (currently unmaintained and Oro 3.X incompatible)

Requirements
-------------------
* Oro Platform 3.X

Installation and Usage
-------------------
**NOTE: Adjust instructions as needed for your local environment**

1. Add to Composer repository list in `composer.json`:
```json
"repositories": {
"customer-tracking-bundle": {
"type": "vcs",
"url": "https://github.com/friendsoforo/OroCustomerTrackingBundle.git",
"no-api": true
}
}
```
1. Install via Composer:
```bash
composer require friendsoforo/oro-customer-tracking-bundle
```
1. Purge Oro cache:
```bash
php bin/console cache:clear --env=prod
```
1. Login to Oro Admin
1. Navigate to **System Configuration => Friends of Oro => Customer Tracking/Analytics**
1. Configure the required Tracking Providers as needed
1. Save the configuration and verify that they are now appearing on the frontend website

Licence
-------------------
[MIT - MIT License](./LICENSE)
12 changes: 12 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "friendsoforo/oro-customer-tracking-bundle",
"license": "MIT",
"description": "Oro Bundle to inject Tracking Code (eg Google Analytics, GTM, LogRocket, Hotjar, etc)",
"type": "project",
"require": {
"oro/platform": "3.*"
},
"autoload": {
"psr-4": { "HackOro\\CustomerTrackingBundle\\": "./src/" }
}
}
47 changes: 47 additions & 0 deletions src/DependencyInjection/CompilerPass/TrackerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* @category HackOro
* @package CustomerTrackingBundle
* @author Chris Rossi <chris.rossi@aligent.com.au>
* @copyright 2019 Aligent Consulting & Friends of Oro
* @license http://opensource.org/licenses/MIT MIT
*/

namespace HackOro\CustomerTrackingBundle\DependencyInjection\CompilerPass;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class TrackerPass implements CompilerPassInterface
{
const TAG = 'hack_oro_customer_tracking.tracker';
const REGISTRY_SERVICE = 'hack_oro_customer_tracking.tracker_registry';

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition(self::REGISTRY_SERVICE)) {
return;
}

$taggedServices = $container->findTaggedServiceIds(self::TAG);

if (empty($taggedServices)) {
return;
}

$trackers = [];
foreach ($taggedServices as $serviceId => $tags) {
$trackers[] = $serviceId;
}

$registryDefinition = $container->getDefinition(self::REGISTRY_SERVICE);

foreach ($trackers as $tracker) {
$registryDefinition->addMethodCall('addTracker', [new Reference($tracker)]);
}
}
}
84 changes: 84 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* @category HackOro
* @package CustomerTrackingBundle
* @author Chris Rossi <chris.rossi@aligent.com.au>
* @copyright 2019 Aligent Consulting & Friends of Oro
* @license http://opensource.org/licenses/MIT MIT
*/

namespace HackOro\CustomerTrackingBundle\DependencyInjection;

use HackOro\CustomerTrackingBundle\Tracker\FullStoryTracker;
use Oro\Bundle\ConfigBundle\Config\ConfigManager;
use Oro\Bundle\ConfigBundle\DependencyInjection\SettingsBuilder;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
// LogRocket
const LOGROCKET_IS_ENABLED = 'logrocket_is_enabled';
const LOGROCKET_APP_ID = 'logrocket_app_id';

// FullStory
const FULLSTORY_IS_ENABLED = 'fullstory_is_enabled';
const FULLSTORY_ORG = 'fullstory_org';
const FULLSTORY_DEBUG_ENABLED = 'fullstory_debug_enabled';
const FULLSTORY_NAMESPACE = 'fullstory_namespace';

// Google Analytics
const GOOGLE_GA_IS_ENABLED = 'google_ga_is_enabled';
const GOOGLE_GA_USER_ID = 'google_ga_user_id';

// Google Tag Manager
const GOOGLE_GTM_IS_ENABLED = 'google_gtm_is_enabled';
const GOOGLE_GTM_USER_ID = 'google_gtm_user_id';

// Hotjar
const HOTJAR_IS_ENABLED = 'hotjar_is_enabled';
const HOTJAR_SITE_ID = 'hotjar_site_id';

/**
* Generates the configuration tree builder.
*
* @return TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root(HackOroCustomerTrackingExtension::ALIAS);

SettingsBuilder::append(
$rootNode,
[
self::LOGROCKET_IS_ENABLED => ['type' => 'boolean', 'value' => false],
self::LOGROCKET_APP_ID => ['type' => 'scalar', 'value' => null],
self::FULLSTORY_IS_ENABLED => ['type' => 'boolean', 'value' => false],
self::FULLSTORY_ORG => ['type' => 'scalar', 'value' => null],
self::FULLSTORY_DEBUG_ENABLED => ['type' => 'boolean', 'value' => false],
self::FULLSTORY_NAMESPACE => [
'type' => 'scalar',
'value' => FullStoryTracker::DEFAULT_NAMESPACE,
],
self::GOOGLE_GA_IS_ENABLED => ['type' => 'boolean', 'value' => false],
self::GOOGLE_GA_USER_ID => ['type' => 'scalar', 'value' => null],
self::GOOGLE_GTM_IS_ENABLED => ['type' => 'boolean', 'value' => false],
self::GOOGLE_GTM_USER_ID => ['type' => 'scalar', 'value' => null],
self::HOTJAR_IS_ENABLED => ['type' => 'boolean', 'value' => false],
self::HOTJAR_SITE_ID => ['type' => 'scalar', 'value' => null],
]
);
return $treeBuilder;
}


/**
* @param string $key
* @return string
*/
public static function getConfigKeyByName($key)
{
return implode(ConfigManager::SECTION_MODEL_SEPARATOR, [HackOroCustomerTrackingExtension::ALIAS, $key]);
}
}
33 changes: 33 additions & 0 deletions src/DependencyInjection/HackOroCustomerTrackingExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* @category HackOro
* @package CustomerTrackingBundle
* @author Chris Rossi <chris.rossi@aligent.com.au>
* @copyright 2019 Aligent Consulting & Friends of Oro
* @license http://opensource.org/licenses/MIT MIT
*/

namespace HackOro\CustomerTrackingBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class HackOroCustomerTrackingExtension extends Extension
{
const ALIAS = 'hack_oro_customer_tracking';

/**
* @inheritdoc
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->prependExtensionConfig($this->getAlias(), $config);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
27 changes: 27 additions & 0 deletions src/HackOroCustomerTrackingBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* @category HackOro
* @package CustomerTrackingBundle
* @author Chris Rossi <chris.rossi@aligent.com.au>
* @copyright 2019 Aligent Consulting & Friends of Oro
* @license http://opensource.org/licenses/MIT MIT
*/

namespace HackOro\CustomerTrackingBundle;

use HackOro\CustomerTrackingBundle\DependencyInjection\CompilerPass\TrackerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class HackOroCustomerTrackingBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new TrackerPass());
}
}
33 changes: 33 additions & 0 deletions src/Layout/DataProvider/CustomerTrackingDataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* @category HackOro
* @package CustomerTrackingBundle
* @author Chris Rossi <chris.rossi@aligent.com.au>
* @copyright 2019 Aligent Consulting & Friends of Oro
* @license http://opensource.org/licenses/MIT MIT
*/

namespace HackOro\CustomerTrackingBundle\Layout\DataProvider;

use HackOro\CustomerTrackingBundle\Tracker\AbstractTracker;
use HackOro\CustomerTrackingBundle\Tracker\TrackerRegistry;

class CustomerTrackingDataProvider
{
/** @var TrackerRegistry */
private $trackerRegistry;

public function __construct(TrackerRegistry $trackerRegistry)
{
$this->trackerRegistry = $trackerRegistry;
}

/**
* @param string $name
* @return AbstractTracker|null
*/
public function getTracker(string $name)
{
return $this->trackerRegistry->getTracker($name);
}
}
2 changes: 2 additions & 0 deletions src/Resources/config/oro/bundles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bundles:
- { name: HackOro\CustomerTrackingBundle\HackOroCustomerTrackingBundle, priority: 1000 }
Loading

0 comments on commit 9ae503d

Please sign in to comment.