Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added order tracking for Google Analytics 4 #3092

Merged
merged 1 commit into from
Apr 11, 2023

Conversation

fballiano
Copy link
Contributor

In #3090 it was pointed out that the previous UA/GA implementation supported the order data tracking, while the GA4 implementation isn't.

This PR aims to add the order tracking to GA4.

Fixed Issues (if relevant)

  1. Fixes Google Analytics 4 / GA4 does not track conversions (orders) #3090

Manual testing scenarios (*)

  1. Enable Analytics 4 in the backend configuration
  2. Place an order
  3. Check that there are no javascript errors and that the order data is sent to analytics

@github-actions github-actions bot added Component: GoogleAnalytics Relates to Mage_GoogleAnalytics Template : base Relates to base template labels Mar 15, 2023
@fballiano fballiano force-pushed the ga4_purchase branch 2 times, most recently from edc19d4 to c46ba48 Compare March 16, 2023 18:47
@sreichel
Copy link
Contributor

Possible to add tax and category information?

@fballiano
Copy link
Contributor Author

I've added the tax amount but I wouldn't add the categories, the trees can be too different from store to store (very deep, with categories with the same names across branches etc) so IMHO we'd some configuration options and multiple implementations for that.

I'll copy paste some code I wrote as a test:

                $categories = [];
                /** @var Mage_Catalog_Model_Category $category */
                foreach ($product->getCategoryCollection() as $category) {
                    $categories[] = $category->getId();
                    foreach ($category->getParentCategories() as $parentCategory) {
                        $categories[] = $category->getId();
                    }
                }
                $categories = array_unique($categories);
                $categoryCollection = Mage::getResourceModel('catalog/category_collection')
                    ->addAttributeToSelect('name')
                    ->addAttributeToFilter('is_active', 1)
                    ->addAttributeToFilter('entity_id', array('in' => $categories));
                $categories = [];
                foreach ($categoryCollection as $category) {
                    $categories[] = $category->getName();
                }
                $categories = array_slice(array_values(array_unique($categories)), 0, 5);
                foreach ($categories as $i => $category) {
                    $i += 1;
                    $i = $i == 1 ? '' : $i;
                    $orderData['item_category' . $i] = $category;
                }

but I'm not committing it, I think we shouldn't have the category for the time being.

@fballiano
Copy link
Contributor Author

@loekvangool could you test this?

@fballiano
Copy link
Contributor Author

@loekvangool?

empiricompany
empiricompany previously approved these changes Mar 30, 2023
@fballiano
Copy link
Contributor Author

This PR is the reason why I won't even take a look at #3121, you develop something that somebody asked, you update it based on someone else's feedback and then nobody cares taking a look at it. neither the person who asked for it nor the other one that asked for modifications...

What a great waste of time.

@ADDISON74
Copy link
Contributor

It's not a waste of time, unfortunately we lack people to allocate a little of their daily time for this project. I wouldn't push things, because there are still a few of us who are moving something around here. I also felt a frustration last year when for a while I didn't see any approved PR.

@sreichel
Copy link
Contributor

sreichel commented Apr 2, 2023

nor the other one that asked for modifications...

Me? I gave thumbs up ... ?!?

empiricompany
empiricompany previously approved these changes Apr 2, 2023
@colinmollenhour colinmollenhour changed the base branch from 1.9.4.x to main April 4, 2023 19:31
@colinmollenhour colinmollenhour dismissed empiricompany’s stale review April 4, 2023 19:31

The base branch was changed.

@colinmollenhour colinmollenhour changed the base branch from main to 1.9.4.x April 4, 2023 19:32
@matteotestoni
Copy link

GA3 stop july. Is possibile approve this before july?

@fballiano
Copy link
Contributor Author

fballiano commented Apr 5, 2023

@matteotestoni if you review it (clicking on the "files changed" and then "review" button) you can make the difference, with 3 reviews with non-admins we can still merge!

matteotestoni
matteotestoni previously approved these changes Apr 5, 2023
@matteotestoni
Copy link

@matteotestoni if you review it (clicking on the "files changed" and then "review" button) you can make the difference, with 3 reviews with non-admins we can still merge!

done

@fballiano
Copy link
Contributor Author

I've to rebase it on the main branch 🤞

@fballiano fballiano changed the base branch from 1.9.4.x to main April 5, 2023 10:55
@github-actions github-actions bot added the Component: Adminhtml Relates to Mage_Adminhtml label Apr 5, 2023
@github-actions github-actions bot removed Component: Page Relates to Mage_Page Component: Uploader Relates to Mage_Uploader Component: ProductAlert Relates to Mage_ProductAlert Component: Poll Relates to Mage_Poll Template : admin Relates to admin template Component: Oauth Relates to Mage_Oauth Component: Eav Relates to Mage_Eav Template : install Relates to install template XML Layout Component: Wishlist Relates to Mage_Wishlist Component: Weee Relates to Mage_Weee Component: Checkout Relates to Mage_Checkout Component: Core Relates to Mage_Core labels Apr 5, 2023
@fballiano fballiano added the Rebased: RFC-0002 This PR has been rebased onto either 'main' or 'next' according to RFC-0002 label Apr 5, 2023
@ADDISON74
Copy link
Contributor

ga

Based on the image above I would like to discuss a few questions

  • When there will be only the "Google Analytics 4" option, do we still need the other options in the Type list?

  • Has anyone used the "IP anonymization" facility so far?

Testing this PR, the script is found in the page source code. Unfortunately I can't make the changes in a production server that I already manage to check what is displayed in the GA interface.

            <!-- BEGIN GOOGLE ANALYTICS 4 CODE -->
        <script async src="https://www.googletagmanager.com/gtag/js?id=ADDISON74"></script>
        <script>
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', 'ADDISON74');
                    </script>
        <!-- END GOOGLE ANALYTICS 4 CODE -->

@fballiano
Copy link
Contributor Author

in the future i'd still leave the select, for an eventual GA5 or whatever.

the IP anonymization I've used it in the past. it's not necessary for GA4 since it's the default and only way the data is sent.

@fballiano fballiano requested review from ADDISON74 and removed request for shyim April 11, 2023 12:22
Copy link
Contributor

@ADDISON74 ADDISON74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approved it because this change must be made ASAP. I appreciate that Google Analytics 4 is the first option in the list. If there will be any issue, I have no doubt that they will not be reported and solved.

@fballiano fballiano merged commit d762104 into OpenMage:main Apr 11, 2023
@fballiano fballiano deleted the ga4_purchase branch April 11, 2023 14:58
@fballiano
Copy link
Contributor Author

merging for 2 gray checks and 1 green.

cherry picked on v19 too since the ga4 implementation wasn't complete but was already merged there.

@fballiano
Copy link
Contributor Author

i've this same code on a customer's website since a while

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: GoogleAnalytics Relates to Mage_GoogleAnalytics documentation environment JavaScript Relates to js/* Rebased: RFC-0002 This PR has been rebased onto either 'main' or 'next' according to RFC-0002 Template : base Relates to base template translations Relates to app/locale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Google Analytics 4 / GA4 does not track conversions (orders)
6 participants