Google Analytics - Manually register pageview using gtag js
I'm new to GA. Let me go straight. I'd like to send page view to GA via Gtag.js from my javascript.
What I tried is I added
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXXXX"></script>
to my landing page.
Then added this to my script
gtag('config', GA_TRACKING_ID,
'page_title': pageTitle,
'user_id': userId,
'page_path': pagePath
);
I can see gtag js loaded however getting error as "Uncaught ReferenceError: gtag is not defined
"
When I added this snippet
window.dataLayer = window.dataLayer || ;
function gtag()
dataLayer.push(arguments);
gtag('js', new Date());
gtag('config', GA_TRACKING_ID,
'page_title': pageTitle,
'user_id': userId,
'page_path': pagePath
);
it stopped giving the error but not sending pageview to GA.
Am I missing something?
javascript c# jquery google-analytics gtag.js
add a comment |
I'm new to GA. Let me go straight. I'd like to send page view to GA via Gtag.js from my javascript.
What I tried is I added
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXXXX"></script>
to my landing page.
Then added this to my script
gtag('config', GA_TRACKING_ID,
'page_title': pageTitle,
'user_id': userId,
'page_path': pagePath
);
I can see gtag js loaded however getting error as "Uncaught ReferenceError: gtag is not defined
"
When I added this snippet
window.dataLayer = window.dataLayer || ;
function gtag()
dataLayer.push(arguments);
gtag('js', new Date());
gtag('config', GA_TRACKING_ID,
'page_title': pageTitle,
'user_id': userId,
'page_path': pagePath
);
it stopped giving the error but not sending pageview to GA.
Am I missing something?
javascript c# jquery google-analytics gtag.js
add a comment |
I'm new to GA. Let me go straight. I'd like to send page view to GA via Gtag.js from my javascript.
What I tried is I added
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXXXX"></script>
to my landing page.
Then added this to my script
gtag('config', GA_TRACKING_ID,
'page_title': pageTitle,
'user_id': userId,
'page_path': pagePath
);
I can see gtag js loaded however getting error as "Uncaught ReferenceError: gtag is not defined
"
When I added this snippet
window.dataLayer = window.dataLayer || ;
function gtag()
dataLayer.push(arguments);
gtag('js', new Date());
gtag('config', GA_TRACKING_ID,
'page_title': pageTitle,
'user_id': userId,
'page_path': pagePath
);
it stopped giving the error but not sending pageview to GA.
Am I missing something?
javascript c# jquery google-analytics gtag.js
I'm new to GA. Let me go straight. I'd like to send page view to GA via Gtag.js from my javascript.
What I tried is I added
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXXXX"></script>
to my landing page.
Then added this to my script
gtag('config', GA_TRACKING_ID,
'page_title': pageTitle,
'user_id': userId,
'page_path': pagePath
);
I can see gtag js loaded however getting error as "Uncaught ReferenceError: gtag is not defined
"
When I added this snippet
window.dataLayer = window.dataLayer || ;
function gtag()
dataLayer.push(arguments);
gtag('js', new Date());
gtag('config', GA_TRACKING_ID,
'page_title': pageTitle,
'user_id': userId,
'page_path': pagePath
);
it stopped giving the error but not sending pageview to GA.
Am I missing something?
javascript c# jquery google-analytics gtag.js
javascript c# jquery google-analytics gtag.js
edited Nov 14 '18 at 8:13
Shubham Sharma
asked Nov 13 '18 at 7:27
Shubham SharmaShubham Sharma
126112
126112
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I guess you missed parameters (page_title and so on) in 2 screenshot.
I missed to add it here. However, I've already added it to my code. Edited question
– Shubham Sharma
Nov 13 '18 at 11:44
@ShubhamSharma How do you check that pageview is sending?
– Ms. Easy
Nov 13 '18 at 12:18
on the network tab (dev console), I can see that it is not sending pageview. When I added this to HTML document it's working perfectly fine. The issue is only when I'm trying to send pageview from the script.
– Shubham Sharma
Nov 13 '18 at 13:18
@ShubhamSharma don't you miss <script></script>? check GA Tracking ID?
– Ms. Easy
Nov 13 '18 at 13:33
I added this to external js file hence no need for <script></script>. Even if the GA tracking ID is incorrect is should at least send the call to Google. It is not even doing that.
– Shubham Sharma
Nov 13 '18 at 14:17
|
show 3 more comments
My Bad. The issue was with GA_TRACKING_ID.
I had one space " " in my GA_TRACKING_ID and it was causing the issue.
Just removing that space worked.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275882%2fgoogle-analytics-manually-register-pageview-using-gtag-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I guess you missed parameters (page_title and so on) in 2 screenshot.
I missed to add it here. However, I've already added it to my code. Edited question
– Shubham Sharma
Nov 13 '18 at 11:44
@ShubhamSharma How do you check that pageview is sending?
– Ms. Easy
Nov 13 '18 at 12:18
on the network tab (dev console), I can see that it is not sending pageview. When I added this to HTML document it's working perfectly fine. The issue is only when I'm trying to send pageview from the script.
– Shubham Sharma
Nov 13 '18 at 13:18
@ShubhamSharma don't you miss <script></script>? check GA Tracking ID?
– Ms. Easy
Nov 13 '18 at 13:33
I added this to external js file hence no need for <script></script>. Even if the GA tracking ID is incorrect is should at least send the call to Google. It is not even doing that.
– Shubham Sharma
Nov 13 '18 at 14:17
|
show 3 more comments
I guess you missed parameters (page_title and so on) in 2 screenshot.
I missed to add it here. However, I've already added it to my code. Edited question
– Shubham Sharma
Nov 13 '18 at 11:44
@ShubhamSharma How do you check that pageview is sending?
– Ms. Easy
Nov 13 '18 at 12:18
on the network tab (dev console), I can see that it is not sending pageview. When I added this to HTML document it's working perfectly fine. The issue is only when I'm trying to send pageview from the script.
– Shubham Sharma
Nov 13 '18 at 13:18
@ShubhamSharma don't you miss <script></script>? check GA Tracking ID?
– Ms. Easy
Nov 13 '18 at 13:33
I added this to external js file hence no need for <script></script>. Even if the GA tracking ID is incorrect is should at least send the call to Google. It is not even doing that.
– Shubham Sharma
Nov 13 '18 at 14:17
|
show 3 more comments
I guess you missed parameters (page_title and so on) in 2 screenshot.
I guess you missed parameters (page_title and so on) in 2 screenshot.
answered Nov 13 '18 at 11:09
Ms. EasyMs. Easy
42117
42117
I missed to add it here. However, I've already added it to my code. Edited question
– Shubham Sharma
Nov 13 '18 at 11:44
@ShubhamSharma How do you check that pageview is sending?
– Ms. Easy
Nov 13 '18 at 12:18
on the network tab (dev console), I can see that it is not sending pageview. When I added this to HTML document it's working perfectly fine. The issue is only when I'm trying to send pageview from the script.
– Shubham Sharma
Nov 13 '18 at 13:18
@ShubhamSharma don't you miss <script></script>? check GA Tracking ID?
– Ms. Easy
Nov 13 '18 at 13:33
I added this to external js file hence no need for <script></script>. Even if the GA tracking ID is incorrect is should at least send the call to Google. It is not even doing that.
– Shubham Sharma
Nov 13 '18 at 14:17
|
show 3 more comments
I missed to add it here. However, I've already added it to my code. Edited question
– Shubham Sharma
Nov 13 '18 at 11:44
@ShubhamSharma How do you check that pageview is sending?
– Ms. Easy
Nov 13 '18 at 12:18
on the network tab (dev console), I can see that it is not sending pageview. When I added this to HTML document it's working perfectly fine. The issue is only when I'm trying to send pageview from the script.
– Shubham Sharma
Nov 13 '18 at 13:18
@ShubhamSharma don't you miss <script></script>? check GA Tracking ID?
– Ms. Easy
Nov 13 '18 at 13:33
I added this to external js file hence no need for <script></script>. Even if the GA tracking ID is incorrect is should at least send the call to Google. It is not even doing that.
– Shubham Sharma
Nov 13 '18 at 14:17
I missed to add it here. However, I've already added it to my code. Edited question
– Shubham Sharma
Nov 13 '18 at 11:44
I missed to add it here. However, I've already added it to my code. Edited question
– Shubham Sharma
Nov 13 '18 at 11:44
@ShubhamSharma How do you check that pageview is sending?
– Ms. Easy
Nov 13 '18 at 12:18
@ShubhamSharma How do you check that pageview is sending?
– Ms. Easy
Nov 13 '18 at 12:18
on the network tab (dev console), I can see that it is not sending pageview. When I added this to HTML document it's working perfectly fine. The issue is only when I'm trying to send pageview from the script.
– Shubham Sharma
Nov 13 '18 at 13:18
on the network tab (dev console), I can see that it is not sending pageview. When I added this to HTML document it's working perfectly fine. The issue is only when I'm trying to send pageview from the script.
– Shubham Sharma
Nov 13 '18 at 13:18
@ShubhamSharma don't you miss <script></script>? check GA Tracking ID?
– Ms. Easy
Nov 13 '18 at 13:33
@ShubhamSharma don't you miss <script></script>? check GA Tracking ID?
– Ms. Easy
Nov 13 '18 at 13:33
I added this to external js file hence no need for <script></script>. Even if the GA tracking ID is incorrect is should at least send the call to Google. It is not even doing that.
– Shubham Sharma
Nov 13 '18 at 14:17
I added this to external js file hence no need for <script></script>. Even if the GA tracking ID is incorrect is should at least send the call to Google. It is not even doing that.
– Shubham Sharma
Nov 13 '18 at 14:17
|
show 3 more comments
My Bad. The issue was with GA_TRACKING_ID.
I had one space " " in my GA_TRACKING_ID and it was causing the issue.
Just removing that space worked.
add a comment |
My Bad. The issue was with GA_TRACKING_ID.
I had one space " " in my GA_TRACKING_ID and it was causing the issue.
Just removing that space worked.
add a comment |
My Bad. The issue was with GA_TRACKING_ID.
I had one space " " in my GA_TRACKING_ID and it was causing the issue.
Just removing that space worked.
My Bad. The issue was with GA_TRACKING_ID.
I had one space " " in my GA_TRACKING_ID and it was causing the issue.
Just removing that space worked.
answered Nov 15 '18 at 6:15
Shubham SharmaShubham Sharma
126112
126112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275882%2fgoogle-analytics-manually-register-pageview-using-gtag-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown