Skip to content

Commit a71d6e3

Browse files
committed
Add customer payload as first script and adjust documentation
1 parent a6261bb commit a71d6e3

6 files changed

Lines changed: 43 additions & 12 deletions

File tree

config/events.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,3 @@ sylius_ui:
55
user_com_configuration:
66
template: '@BitBagSyliusUserComPlugin/UserApiResource/_userComCredentials.html.twig'
77
priority: 25
8-
sylius.shop.layout.stylesheets:
9-
blocks:
10-
user_com:
11-
template: '@BitBagSyliusUserComPlugin/_userComScripts.html.twig'
12-
priority: 25

doc/installation.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,10 @@
5555
6. Take advantage of channel based configuration of GoogleAnalyticsPlugin by adding :
5656
```yaml
5757
spinbits_sylius_google_analytics4:
58-
id: "%env(TAG_MANAGER_ID)%"
58+
id: "%env(TAG_MANAGER_ID)%"
59+
templateName: "@BitBagSyliusUserComPlugin/_userComScripts.html.twig"
60+
enabled: true
5961
```
62+
7. Add api credentials to your channel configuration in admin panel. If you decided to extend different object, please make sure that api credentials are set
63+
64+
8. While integrating with User.com via GTM, you can use `user_com_customer_info` in browser console to check currently logged in customer data.

src/Trait/UserComApiAwareInterface.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313

1414
interface UserComApiAwareInterface
1515
{
16-
public function getId(): mixed;
16+
/**
17+
* To ensure compatibility with ResourceInterface, return type must be missing
18+
*
19+
* @phpstan-ignore-next-line
20+
*/
21+
public function getId();
1722

1823
public function getUserComUrl(): ?string;
1924

templates/_userComScripts.html.twig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,29 @@
2424
{% endif %}
2525
</script>
2626
{% endif %}
27+
28+
<!-- Google tag (gtag.js), plugin provided by Spinbits -->
29+
{% dump %}
30+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ id }}{{ url_suffix|raw }}"></script>
31+
<script>
32+
window.dataLayer = window.dataLayer || [];
33+
function gtag(){window.dataLayer.push(arguments);}
34+
gtag('js', new Date());
35+
gtag('config', '{{ id }}');
36+
if (window.performance) {
37+
gtag('event', 'timing_complete', {
38+
'name': 'load',
39+
'value': Math.round(performance.now()),
40+
'event_category': 'JS Dependencies'
41+
});
42+
}
43+
{% if app.session is not null and app.session.started %}
44+
{% set events = app.session.bag('spinbits_ga4_events').all %}
45+
{% for event, content in events %}
46+
{% for c in content %}
47+
gtag("event", "{{ event }}", {{ c|raw }});
48+
{% endfor %}
49+
{% endfor %}
50+
console.log({{ events|json_encode|raw }})
51+
{% endif %}
52+
</script>

tests/Application/config/packages/_sylius.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ sylius_channel:
2424
channel:
2525
classes:
2626
model: Tests\BitBag\SyliusUserComPlugin\Entity\Channel
27+
28+
spinbits_sylius_google_analytics4:
29+
id: "%env(TAG_MANAGER_ID)%"
30+
templateName: "@BitBagSyliusUserComPlugin/_userComScripts.html.twig"
31+
enabled: true

tests/Application/config/packages/events.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,3 @@ sylius_ui:
55
user_com_configuration:
66
template: '@BitBagSyliusUserComPlugin/UserApiResource/_userComCredentials.html.twig'
77
priority: 25
8-
sylius.shop.layout.stylesheets:
9-
blocks:
10-
user_com:
11-
template: '@BitBagSyliusUserComPlugin/_userComScripts.html.twig'
12-
priority: 25

0 commit comments

Comments
 (0)