Skip to content

Commit

Permalink
#1274 Upgrade to Google Analytics 4
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz committed Oct 9, 2023
1 parent 97ed4ac commit 98c7375
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 58 deletions.
24 changes: 14 additions & 10 deletions app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
<link rel="icon" type="image/png" sizes="64x64" href="{{ asset('/images/favicon.png') }}">
<link rel="apple-touch-icon" sizes="57x57" href="{{ asset('/images/apple-touch-icon.png') }}">
<link rel="alternate" type="application/rss+xml" title="Le flux RSS de l'AFUP" href="{{ path('feed_rss') }}" />
{% if google_analytics_enabled %}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', '{{ google_analytics_id }}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}

{% block google_analytics %}
{% if google_analytics_enabled %}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ google_analytics_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ google_analytics_id }}');
</script>
{% endif %}
{% endblock %}
</head>
<body id="body" class="{% block body_css %}{% endblock %}">
<a class="evitement" href="#contenu">Aller au contenu</a>
Expand Down
91 changes: 46 additions & 45 deletions app/Resources/views/event/ticket/payment.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
<link rel="stylesheet" href="{{ asset('/css/tickets.css') }}" />
{% endblock %}

{% block google_analytics %}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ google_analytics_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ google_analytics_id }}');
</script>
{% endblock %}

{% block content %}
<div class="col-md-8">
{% if not invoice.isFree %}
Expand Down Expand Up @@ -45,70 +57,59 @@
<p>
Nous avons bien re&ccedil;u votre inscription et nous vous en remercions !
</p>
Si vous avez la moindre question, n'hésitez pas à contacter <a href="mailto:[email protected]">[email protected]</a>.
<p>
Si vous avez la moindre question, n'hésitez pas à contacter <a href="mailto:[email protected]">[email protected]</a>.
</p>
<p>Vous allez recevoir dans quelques instants la facture à l'adresse email de facturation.</p>
</div>
{% endif %}
</div>

{% autoescape 'js' %}
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-67701567-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- Google Code for Inscription evenement Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 878368884;
var google_conversion_language = "fr";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "HBjSCKivn2oQ9LDrogM";
var google_conversion_value = {{ invoice.amount }};
var google_conversion_currency = "EUR";
var google_remarketing_only = false;
var google_conversion_id = 878368884;
var google_conversion_language = "fr";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "HBjSCKivn2oQ9LDrogM";
var google_conversion_value = {{ invoice.amount }};
var google_conversion_currency = "EUR";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/878368884/?value=250.00&amp;currency_code=EUR&amp;label=HBjSCKivn2oQ9LDrogM&amp;guid=ON&amp;script=0"/>
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/878368884/?value={{ invoice.amount }}&amp;currency_code=EUR&amp;label=HBjSCKivn2oQ9LDrogM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

<script>
_gaq = _gaq || [];
_gaq.push(['_addTrans',
'{{ invoice.reference }}',// transaction ID - required
'{{ event.title }}', // affiliation or store name
'{{ invoice.amount }}', // total - required; Shown as "Revenue" in the
// Transactions report. Does not include Tax and Shipping.
'0', // tax
'0', // shipping
'{{ invoice.city }}', // city
'', // state or province
'{{ invoice.countryId }}' // country
]);
{% for ticket in tickets %}
_gaq.push(['_addItem',
'{{ invoice.reference }}', // transaction ID - necessary to associate item with transaction
'{{ ticket.ticketTypeId }}', // SKU/code - required
'{{ ticket.ticketEventType.ticketType.prettyName }}', // product name
'', // category or variation
'{{ ticket.amount }}', // unit price - required
'1' // quantity - required
]);
{% endfor %}
_gaq.push(['_trackTrans']);
// This purchase event uses a different transaction ID
// from the previous purchase event so Analytics
// doesn't deduplicate the events.
// Learn more: https://support.google.com/analytics/answer/12313109
gtag("event", "purchase", {
transaction_id: "{{ invoice.reference }}",
value: {{ invoice.amount }},
tax: 0,
shipping: 0,
currency: "EUR",
items: [
{% for ticket in tickets %}
{
item_id: "{{ invoice.reference }}",
item_name: "{{ ticket.ticketEventType.ticketType.prettyName }}",
index: {{ loop.index }},
price: {{ ticket.amount }},
quantity: 1
},
{% endfor %}
]
});
</script>
{% endautoescape %}
{% endblock %}
2 changes: 1 addition & 1 deletion app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ parameters:
super_apero_csv_url: ""

google_analytics_enabled: false
google_analytics_id: "UA-192127-3"
google_analytics_id: "G-CHPWDR3C1M"

techletter_test_email_address: "[email protected]"

Expand Down
2 changes: 1 addition & 1 deletion app/config/parameters.yml.dist-docker
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ parameters:
super_apero_csv_url: ""

google_analytics_enabled: false
google_analytics_id: "UA-192127-3"
google_analytics_id: "G-CHPWDR3C1M"

techletter_test_email_address: "[email protected]"

Expand Down
2 changes: 1 addition & 1 deletion sources/AppBundle/Controller/Admin/HomeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __invoke()
{
$nextevents = $this->eventRepository->getNextEvents();
$cards = [];
if ($this->security->isGranted('ROLE_FORUM')) {
if ($this->security->isGranted('ROLE_FORUM') && $nextevents) {
foreach ($nextevents as $event) {
$stats = $this->eventStatsRepository->getStats($event->getId());
$info = [];
Expand Down

0 comments on commit 98c7375

Please sign in to comment.