Skip to content

Commit

Permalink
Merge pull request afup#1321 from stakovicz/feat-upgrade-google-analy…
Browse files Browse the repository at this point in the history
…tics-4

afup#1274 Upgrade to Google Analytics 4
  • Loading branch information
stakovicz authored Oct 17, 2023
2 parents c23187d + 6c24a04 commit a19d4f7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 57 deletions.
16 changes: 6 additions & 10 deletions app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@
<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 %}
{% include 'google_analytics.html.twig' %}
{% endif %}
{% endblock %}
</head>
<body id="body" class="{% block body_css %}{% endblock %}">
<a class="evitement" href="#contenu">Aller au contenu</a>
Expand Down
83 changes: 38 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,10 @@
<link rel="stylesheet" href="{{ asset('/css/tickets.css') }}" />
{% endblock %}

{% block google_analytics %}
{% include 'google_analytics.html.twig' %}
{% endblock %}

{% block content %}
<div class="col-md-8">
{% if not invoice.isFree %}
Expand Down Expand Up @@ -45,70 +49,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 %}
9 changes: 9 additions & 0 deletions app/Resources/views/google_analytics.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- 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>
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

0 comments on commit a19d4f7

Please sign in to comment.