From 9ee52948010eeb36c634bb89481fe1bc93d1241a Mon Sep 17 00:00:00 2001 From: Dan Tovbein Date: Wed, 16 Oct 2024 06:57:20 -0300 Subject: [PATCH] PLANET-7575: Rename social media events (#2351) * PLANET-7575: Rename social media events Ref: https://jira.greenpeace.org/browse/PLANET-7575 - Keep "uaevent" and add "page_shared" - Also add "channel" variable --- assets/src/blocks/ENForm/ShareButtons.js | 14 +++++- src/GravityFormsExtensions.php | 1 + templates/blocks/share_buttons.twig | 59 +++++++++++------------- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/assets/src/blocks/ENForm/ShareButtons.js b/assets/src/blocks/ENForm/ShareButtons.js index cdc7175667..e893230037 100644 --- a/assets/src/blocks/ENForm/ShareButtons.js +++ b/assets/src/blocks/ENForm/ShareButtons.js @@ -27,11 +27,21 @@ export const ShareButtons = ({social_params, social_accounts}) => { } = social_params; const share = (action, label) => { - window.dataLayer.push({ - event: 'uaevent', + const shared = { eventCategory: 'Social Share', eventAction: action, eventLabel: label, + }; + + window.dataLayer.push({ + event: 'uaevent', + ...shared, + }); + + window.dataLayer.push({ + event: 'page_shared', + channel: action, + ...shared, }); }; diff --git a/src/GravityFormsExtensions.php b/src/GravityFormsExtensions.php index 57cec81b6e..ca25ce3a20 100644 --- a/src/GravityFormsExtensions.php +++ b/src/GravityFormsExtensions.php @@ -282,6 +282,7 @@ public function p4_gf_custom_initial_settings(array $form, bool $is_new): void "gaeventlabel_thickbox" => "{form_title} ID: {form_id}", "gaeventgoalid" => "", "gaeventgoal" => "Submission: " . $form['title'], + "channel" => "", "gaeventcategory" => "", "gaeventaction" => "", "gaeventlabel" => "{form_title} ID: {form_id}", diff --git a/templates/blocks/share_buttons.twig b/templates/blocks/share_buttons.twig index 7bc6571bca..99dc1958f8 100644 --- a/templates/blocks/share_buttons.twig +++ b/templates/blocks/share_buttons.twig @@ -1,41 +1,38 @@ {% block javascripts %} - + window.nativeShare = async () => { + try { + await navigator.share({ + title: '{{ social.title }}', + url: '{{ share_url ?? social.link }}', + text: '{{ share_text ?? social.description }}', + }); + dataLayerPush('Native'); + } catch (err) { + console.log(err); + } + }; + } + {% endblock %} {% set socialLink = (share_url ?? social.link) ~ '?utm_medium=' ~ utm_medium ~ utm_content_param ~ utm_campaign_param %}