I’m trying to setup ecommerce event configuration of Google Analytics App+Web for a website. Refer to the documentation here.
Because there is a lot of custom code for the ecommerce configuration, I cannot use the general GA App+Web webevent template, so instead I’m using a custom HTML-tag in this case.
As a first test, I tried to fire the following simple event:
<script>
gtag('event', 'blabla', {
'test_param1': 'test_value_1'
});
</script>
However, the event is not correctly sent to GA; instead, the following error in the console is returned:
Uncaught ReferenceError: gtag is not defined
To reproduce, see the following page: https://www.hema.nl/mooi-gezond/make-up/make-up-accessoires/toilettassen-1/toilettas-11830901.html
Additional information:
- The GA App+Web base initialization is (successfully) done via GTM, via the GA App+Webconfiguration template tag.
- I also configured a few other (simple non-ecommerce) GA App+Web events via GTM via the GA App+Web webevent template tag , and these events are sent to GA successfully.
Does anyone know what’s going wrong, why the console error appears and why the event is not sent to GA?
asked Apr 5, 2020 at 10:26
![]()
Short answer
Additionally to the GTM GA App+Web tag, you need to add the following code to have gtag() defined:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
</script>
Long answer
According to the official documentation (https://developers.google.com/analytics/devguides/collection/ga4) this is the code you should include in your site:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'MEASUREMENT_ID');
</script>
After inspecting a website with this tag I found GTM has injected that first line, which is enough to make analytics work. But it didn’t add the other lines, some of which effectively defines the gtag global function as a «syntax sugar» for pushing things to the Analytics Data Layer.
Personally, I find this really strange, since using GTM is the most cannonical of adding Google Analytics to a website and it’s by the same company.
answered Feb 21, 2021 at 13:27
3
The cause of the problem has been found. The problem seemed to be that gtag() does not work if the App+Web base setup is done with the GTM App+Web base template tag. Instead, an event should first be pushed to the GTM datalayer, and then the GTM App+Web event template should be used to send the event to Google Analytics.
Lots of thanks Gino (working at Merkle) for fixing the issue!
answered Apr 7, 2020 at 12:48
![]()
Timo RietveldTimo Rietveld
3831 gold badge5 silver badges19 bronze badges
1
In my case Uncaught ReferenceError: gtag is not defined was caused by uBlock/adblock turned on.
I think it’s worth testing if accepted answer doesn’t work.
answered Oct 4, 2021 at 8:58
dpatryasdpatryas
2903 silver badges11 bronze badges
2022 Year answer:
For anyone struggling with using GA4 gtag and GTM (Google Tag Manager) simultaniously in your SPA/Angular/React app, you should do next:
- don’t use built-in GTM’s «Google Analytics: GA4 Configuration» tag configuration
- do use «Custom HTML» GTM tag with exactly that
gtagJS code from your Google Analytics, i.e.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
</script>
After that you can use gtag in your code as you intended to do, all should work. No whole Firebase needed or something. Possibly you will need to have
gtag('config', 'GA_MEASUREMENT_ID', {
send_page_view: false
});
to disable automatic page_view tracking.
answered Apr 12, 2022 at 14:06
If you’re using Google Tag Manager, the gtag function doesn’t exist. Follow this guide to create custom events
Basically the code you use is
dataLayer.push({event: 'event_name'});
Then you setup a tag in GTM for GA4 event. Use the event name that you want to see in Google analytics. For the trigger, use custom event. Here, in the event name, use the name that you used in your code event_name
answered Oct 31, 2021 at 15:14
![]()
WhipWhip
1,60719 silver badges41 bronze badges
I found out that it was due to an AD Blocking Extensions added to my chrome
answered Feb 19, 2022 at 13:41
![]()
植植心植植心
3672 silver badges4 bronze badges
JavaScript
Sep 19, 2019
·
Updated: Jul 12, 2021 · by Tim Kamanin
Are you staring at a pesky «Uncaught ReferenceError: ga is not defined» console error message right now?
Yeah, I feel your pain, I’ve just lost two hours of my life figuring it out. Let me save this time for you.
This message means ga is not available for the code that tries to use it. And ga stands for «Google Analytics». ga is a global object used by the legacy analytics.js snippet.
Let’s troubleshoot
-
Open a debug console and type:
window.ga. Did you get undefined? If yes, that go to the next step. If not, then your problem is in code order. Make sure https://www.google-analytics.com/analytics.js gets included before you callga()function. This one is easy, and that wasn’t my case. Let’s move on. -
Okay, so
window.gasays «undefined» to you. If you’re sure that Google analytics is enabled on your website (via wordpress/drupal or whatever else plugin, just like in my case), the only reason why it’s still not working is because your website includes Google analytics in a modern, «Global Site Tag» way. View a source of your page and try to locate ahttps://www.googletagmanager.com/gtag/jsstring. Got it? Yeah, right. It means you can’t usega()in your code and you need either:a. Rollback to the legacy
analytics.jscode, orb. convert existing code, so it’s compatible with
gtag.js. Read here for more info on migrating from analytics.js to gtag.js.
My case
My issue was related to Google Optimize. Every doc and tutorial was telling me to use ga('require', 'GTM-XXXXXX'); to enable Google Optimize container. But since I had Google Analytics included as gtag.js I needed to use:
gtag("config", "UA-GA_TRACKING-CODE", { optimize_id: "GTM-XXXXXX" });
Did it help? You’re welcome! Follow me on Twitter @timonweb and let me know if this post was helpful.
Hey, if you’ve found this useful, please share the post to help other folks find it:
Ecommerce Marketing
SEO, AdWords, affiliates, advertising, and promotions
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Show only
|
Search instead for
Did you mean:
To continue receiving payouts, you need to secure your account by turning on two-step authentication. If two-step authentication is not turned on your payouts will be paused. Learn more
-
Shopify Community
-
Shopify Discussion
-
Ecommerce Marketing
- gtag is not defined on Thank you page
Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
-
All forum topics -
Previous Topic -
Next Topic
Next topic
Replies 3 (3)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2019
10:55 PM
Just keep in mind you just need to insert UA-…. code into the Google Analytics account field.
Don’t forget to enable «Enhanced Ecommerce» to track Conversion Report of GA.
Found my answer helpful? Please LIKE or Accept Solutions.
Top 30 Best Shopify Themes Free + Premium: A Complete Review Read More
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019
02:55 AM
Hii,
I think you are talking about GTM code setup first check gtag code is it properly inserted in the backend of the website . It should be properly inserted in the head and body section of a website. After this, you can check in google tag manager in the preview section.
Once you will verify it you can track analytics and other tracking data for other queries you can contact me.
MageNative | Mobile App for your Shopify Store | Native Android and iOS Apps
Digital Marketing Analyst
Skype: live:asthaupadhyay_1
E-mail: asthaupadhyay@magenative.com
![]()
- All Unanswered Topics
- Community Blog
- Community Guidelines
- Code of Conduct
- Terms of Service
- Privacy Policy
-
Shopify Community-


Shopify Discussion-

Shopify Discussions -

Store Feedback -

Shopify Design -

Announcements -

Shopify Apps -

Shopify Translate & Adapt -

Ecommerce Marketing -

Technical Q&A -

Site Speed -

Retail and Point of Sale -

International Commerce -

Payments, Shipping, and Fulfillment -

Accounting and Taxes -

Wholesale and Dropshipping -

Shopify Flow App -

Shopify Scripts -

Jobs and Careers
-
-


Partners and Developers-

Shopify APIs and SDKs -

Sales Channels, Payments Platform & Wallet API -

Storefront API and SDKs -

Subscription APIs -

Online Store 2.0 -

Fulfillment API Deprecation -

Shopify Functions
-
-


Groups-


Regional -

Education -

Voices -


Products & Services
-
-

English video guides and tutorials -

Blog
-
Community Blog Articles
-
Shopify Community
Shopify Design
Shopify Discussions
Shopify APIs and SDKs
Technical Q&A
Payments, Shipping, and Fulfillment -
Support
24/7 Support
Shopify Help Center
API documentation
Free Tools -
Shopify
Contact
Partner Program
Affiliate Program
App Developers
Investors -
Quick Links
Register
Log in
Adobe Analytics Coffee Break: On Monday, January 30 at 10am PT, the NOAM User Group led by Jennifer Dungan and Jeff Bloomer will be joining us to answer your Analytics related questions. To register and for more information, follow the link to the right.
Dear All,
We need to check that Google floodlight pixel working or not so we need to check Gtag(Global site tag) and then we typed gtag in console and its showing gtag is not defined.
It means gtag is missing/removed right?
Also I would like to know that in how many ways we can check this «how to identify gtag is present or not.»
Thank you
1 Accepted Solution
How have you implemented gtag?
Normally, you can query for gtag in the browser console, like what you’ve done. You could also install the Google Tag Assistant extension in your browser and see if it detects the Google tags appropriately.
-
All forum topics -
Previous Topic -
Next Topic
1 Reply
How have you implemented gtag?
Normally, you can query for gtag in the browser console, like what you’ve done. You could also install the Google Tag Assistant extension in your browser and see if it detects the Google tags appropriately.
![]()