Skip to content

Commit

Permalink
Merge pull request #4912 from yKazihara/feature/google_analytics
Browse files Browse the repository at this point in the history
Googleアナリティクス機能を追加
  • Loading branch information
dotani1111 authored Apr 8, 2024
2 parents 3f62b87 + 99e81da commit 3c9b2a1
Show file tree
Hide file tree
Showing 12 changed files with 526 additions and 393 deletions.
33 changes: 33 additions & 0 deletions app/DoctrineMigrations/Version20210216120000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210216120000 extends AbstractMigration
{
public function up(Schema $schema): void
{
// データ存在チェック
$count = $this->connection->fetchColumn("SELECT COUNT(*) FROM dtb_block WHERE block_name = 'Googleアナリティクス'");
if ($count > 0) {
return;
}

// idを取得する
$id = $this->connection->fetchColumn('SELECT MAX(id) FROM dtb_block');
$id++;

$this->addSql("INSERT INTO dtb_block (id, block_name, file_name, use_controller, deletable, create_date, update_date, device_type_id, discriminator_type) VALUES ($id, 'Googleアナリティクス', 'google_analytics', false, false, '2021-02-16 12:00:00', '2021-02-16 12:00:00', 10, 'block')");
$this->addSql("INSERT INTO dtb_block_position (section, block_id, layout_id, block_row, discriminator_type) VALUES (1, $id, 1, 0, 'blockposition')");
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
31 changes: 31 additions & 0 deletions src/Eccube/Entity/BaseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ class BaseInfo extends \Eccube\Entity\AbstractEntity
*/
private $Pref;

/**
* @var string|null
*
* @ORM\Column(name="ga_id", type="string", length=255, nullable=true)
*/
private $gaId;

/**
* Get id.
*
Expand Down Expand Up @@ -1142,5 +1149,29 @@ public function setPhpPath($php_path)

return $this;
}

/**
* Set gaId.
*
* @param string|null $gaId
*
* @return BaseInfo
*/
public function setGaId($gaId = null)
{
$this->gaId = $gaId;

return $this;
}

/**
* Get gaId.
*
* @return string|null
*/
public function getGaId()
{
return $this->gaId;
}
}
}
8 changes: 8 additions & 0 deletions src/Eccube/Form/Type/Admin/ShopMasterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]),
],
])
->add('ga_id', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_stext_len'],
]),
],
])
;

$builder->add(
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/doctrine/import_csv/en/dtb_block.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ id,device_type_id,block_name,file_name,create_date,update_date,use_controller,de
12,10,News,news,2017-03-07 10:14:52,2017-03-07 10:14:52,0,0,block
13,10,Product Search,search_product,2017-03-07 10:14:52,2017-03-07 10:14:52,1,0,block
14,10,Featured,topic,2017-03-07 10:14:52,2017-03-07 10:14:52,0,0,block
16,10,Google Analytics,google_analytics,2021-02-16 12:00:00,2021-02-16 12:00:00,0,0,block
17,10,Calendar,calendar,2021-03-16 12:00:00,2021-03-16 12:00:00,1,0,block
18,10,Auto New Items,auto_new_item,2024-03-12 17:00:00,2024-03-12 17:00:00,1,0,block
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
"11","13","2","1","blockposition"
"11","4","2","2","blockposition"
"11","9","2","3","blockposition"
"1","16","1","0","blockposition"
1 change: 1 addition & 0 deletions src/Eccube/Resource/doctrine/import_csv/ja/dtb_block.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"12","10","新着情報","news","2017-03-07 10:14:52","2017-03-07 10:14:52","0","0","block"
"13","10","商品検索","search_product","2017-03-07 10:14:52","2017-03-07 10:14:52","1","0","block"
"14","10","トピック","topic","2017-03-07 10:14:52","2017-03-07 10:14:52","0","0","block"
"16","10","Googleアナリティクス","google_analytics","2021-02-16 12:00:00","2021-02-16 12:00:00","0","0","block"
"17","10","カレンダー","calendar","2021-03-16 12:00:00","2021-03-16 12:00:00","1","0","block"
"18","10","新着商品(自動取得)","auto_new_item","2024-03-12 17:00:00","2024-03-12 17:00:00","1","0","block"
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
"11","13","2","1","blockposition"
"11","4","2","2","blockposition"
"11","9","2","3","blockposition"
"1","16","1","0","blockposition"
443 changes: 221 additions & 222 deletions src/Eccube/Resource/locale/messages.en.yaml

Large diffs are not rendered by default.

339 changes: 169 additions & 170 deletions src/Eccube/Resource/locale/messages.ja.yaml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/Eccube/Resource/template/admin/Setting/Shop/shop_master.twig
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,23 @@ file that was distributed with this source code.
</div>
</div>
</div>
<div class="card rounded border-0 mb-4">
<div class="card-header"><span>{{ 'admin.setting.shop.shop.ga'|trans }}</span></div>
<div id="ex-shop-ga" class="card-body">
<div class="row mb-3">
<div class="col-3">
<div class="d-inline-block" data-tooltip="true" data-placement="top" title="{{ 'tooltip.setting.shop.shop.ga.tracking_id'|trans }}">
<span>{{ 'admin.setting.shop.shop.ga.tracking_id'|trans }}</span>
<i class="fa fa-question-circle fa-lg ml-1"></i>
</div>
</div>
<div class="col mb-2">
{{ form_widget(form.ga_id, { attr : { placeholder : 'admin.common.ga.tracking_id' }} ) }}
{{ form_errors(form.ga_id) }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
21 changes: 21 additions & 0 deletions src/Eccube/Resource/template/default/Block/google_analytics.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{#
This file is part of EC-CUBE
Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
http://www.ec-cube.co.jp/
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}
{% if BaseInfo.ga_id is not empty %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ BaseInfo.ga_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ BaseInfo.ga_id }}');
</script>
{% endif %}
23 changes: 22 additions & 1 deletion tests/Eccube/Tests/Web/TopControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
namespace Eccube\Tests\Web;

use Eccube\Entity\BaseInfo;
use Eccube\Entity\Page;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\Master\OrderStatusRepository;
use Eccube\Entity\Page;
use Eccube\Repository\PageRepository;

class TopControllerTest extends AbstractWebTestCase
Expand All @@ -33,6 +34,26 @@ public function testCheckFavicon()
$this->assertEquals('/html/user_data/assets/img/common/favicon.ico', $node->attr('href'));
}

public function test_GAスクリプト表示確認()
{
// GAスクリプト表示がある時
$BaseInfo = $this->entityManager->getRepository(BaseInfo::class)->get();
$BaseInfo->setGaId('UA-12345678-1');
$this->entityManager->flush();

$crawler = $this->client->request('GET', $this->generateUrl('homepage'));
$node = $crawler->filterXPath('//script[contains(@src, "googletagmanager")]');
$this->assertEquals('https://www.googletagmanager.com/gtag/js?id=UA-12345678-1', $node->attr('src'));

// GAスクリプト表示がない時
$BaseInfo->setGaId('');
$this->entityManager->flush();

$crawler = $this->client->request('GET', $this->generateUrl('homepage'));
$node = $crawler->filterXPath('//script[contains(@src, "googletagmanager")]');
$this->assertEmpty($node);
}

/**
* TOPページ metaタグのテスト
*/
Expand Down

0 comments on commit 3c9b2a1

Please sign in to comment.