Universal Analytics not working correctly - events

I'm updating the old analytics to Universal Analytics, but i'm having problems.
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-X', 'website.com');
ga('send', 'pageview');
</script>
That's is the new code i pasted in my head file. But when i use de Analytics debugger (for Chrome) and i run a command like:
ga("send", "event", "navigation", "Click", "Home");
I get a error like this (in debugger):
Command ignored. Unknown target: undefined
I'm getting realtime data in analytics, so i know that the code is working for simple tracking. Event tracking is the problem.
Can somebody help me?

Command ignored. Unknown target: undefined
This mean that your tracker is not initialized correctly or it is not initialized and you are trying to send data on them.
Problem
Problem should be ga('create', 'UA-XXXXXXX-X', 'website.com'); where you set website.com
The question is: Are your events fired from same domain? This should be equal to document.location.hostname.
Testing
For testing, try it with auto parameter as cookieDomain. If this works, focus your energy into cookieDomain area.
Other possibilities
Some people reach this issue in different was, try to learn from them:
Existing Google Analytics events and Google Tag Manager
Google Universal Analytics - Command ignored
Documentation
https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#cookieDomain

Related

How to include reCAPTCHA v3 in the background of pages?

In the reCAPTCHA v3 docs, it says
reCAPTCHA works best when it has the most context about interactions with your site, which comes from seeing both legitimate and abusive behavior. For this reason, we recommend including reCAPTCHA verification on forms or actions as well as in the background of pages for analytics.
How do we run it in the background of pages?
Let's say I have a React app that handles multiple web pages, and for one of my web pages, it is a sign up form where I want to get a risk score when users sign up. When the docs say to run reCAPTCHA in the background on other pages, does that mean it's running on other pages as long as <script src="https://www.google.com/recaptcha/api.js?render=_reCAPTCHA_site_key"></script> is in the header? Or do we need to call grecaptcha.execute(...) on all the other pages, and not just the signup page?
As long as you have the script attached, it will run in the background of pages. You can see that it's running if the reCAPTCHA banner/icon is showing on the page (usually bottom right corner). grecaptcha.execute(...) should be run on a specific action, like when you click a button to sign up for example.
#jojochuu, your answer is exactly right. Thanks for that.
I found another reason to run grecaptcha.execute. Logging. Loading api.js (the second line in the code below) is sufficient to activate recaptcha. It displays the flyout recptcha button.
I chose to add the second script that does call grecaptcha and gets the token. Then I use the token to get the score and any error codes from google. I log that data along with the visitor's IP address and a timestamp so I can see how the score changes over time. I can then compare my logs with access logs and maybe spot some IPs I want to ban. Mostly, I just want to know how score changes. I'll disable the logging by removing the second script block.
This is the best tutorial I found. Combining it with the google docs was enough to learn how to do recaptcha right.
<input type="hidden" id="visitor_ip" value="<?=$visitor_ip; ?>">
<script src="https://www.google.com/recaptcha/api.js?render=public-site-key" async defer></script>
<script>
// This correctly gets the token, but doesn't verify the user response (action).
function execGrecaptcha() {
grecaptcha.ready(function() {
grecaptcha.execute('<?=$settings->recap_public; ?>', {action: '<?=$actionName; ?>'}).then(function(token) {
logRecaptchaResults(token);
});
});
}
// Run after page loaded
window.onload=execGrecaptcha;
// Send token/ip to server for logging via ajax
function logRecaptchaResults(token) {
var vip=document.getElementById('visitor_ip');
$.ajax({
url: "https://<?=HOST_NAME_DOT; ?>domain.com/ajax/logit.php",
type: "get", //send it through get method
data: {
"token": token,
"visitor_ip": vip.value
},
});
}
</script>

Google Tag Manager - Create Event with Inline onclick attribute

I have a website where I am using Google Tag Manager to fire my Google Analytics tracking.
<!-- Google Tag Manager -->
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','********');
</script>
<!-- End Google Tag Manager -->
On the page, I wanted to track link clicks that open a modal window.
So, I put this code:
onclick="ga('send', 'event', 'Test', 'Take-Test', 'English');"
However, that is not working and it's not pushing the event into Analytics.
After doing a lot of digging, I thought maybe the issue is that GTM uses gtag.js instead of the older analytics.js library, so the structure of my onclick event had to be different.
My source for this was: https://developers.google.com/analytics/devguides/collection/gtagjs/migration#track_events
Based on this, I'm thinking my onclick event has to look like this:
onclick="gtag('event', 'Take-Test', {'event_category': 'test','event_label': 'English'});
However, I can't seem to confirm that with a GTM implementation it is using gtag.js, so I don't know if this is correct still.
All I know is that I really want to push this event into Analytics properly.
As a side note, I realize I can probably create GTM firing rules for this, however for reasons beyond my control, I have to create the onclick event in the HTML code and not via GTM.
Many thanks in advance for any insight!
Your ga('send' ...) call would not work in this case because
GTM automatically sets unique tracker names for its tags, which will not match the tracker name of your on-page analytics object.
(cf. https://www.lunametrics.com/blog/2015/01/21/gtm-existing-tracking/)
You would either have to find out the tracker name that GTM is using and modify your send call to something like this
ga('trackerName.send', 'event', ...)
or track the click using a GTM tag.
A bit old thread but anyway.
Had the same problem until I put this at the top of page:
<script>window.onload = function(){
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-X');
ga('create', 'UA-XXXXXXXX-X');
.......
Especially the ga('create', 'UA-XXXXXXXX-X') seems to be crucial.
Maybe you should use analytics.js instead of ga.js:
https://developers.google.com/analytics/devguides/collection/analyticsjs/events
ga('create', 'UA-IDHERE-X', 'auto');
ga('send', {
hitType: 'event',
eventCategory: 'Your Category',
eventAction: 'Your Action',
eventLabel: 'Your Label'
});

js in html is not executing in Phoenix framework sample app

I'm playing around with the phoenix framework. I copied the chat example entirely but I'm not getting any results.
In fact when I write console.log("testing") in my app.js I notice that my console does not log anything...
I am getting the error referenced in this link:
phoenix framework - invalid argument at new Socket - windows
However that error seems to be related to Brunch not working in windows. When I brunch build, I can confirm that app.js has the console.log("testing") that I included.
Nevertheless, I don't see that console log when I visit my localhost:4000.
Why is JS not executing?
Turns out the guide is missing a key line that made it not work.
The guide has the following:
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="<%= static_path(#conn, "/js/app.js") %>"></script>
</body>
But that is missing the below line which you can put above the body tag.
<script>require("web/static/js/app")</script>
Even as Chowza already solved this question I would like to propose another, possible cleaner solution, using the autoRequire feature of Brunch.io.
The problem occurs because Brunch.io does not autoRequire the app.js under Windows correctly. Chowza worked around this issue by requiring the file manually in the html. You can omit the manual require if you alter the /brunch-config.js as follows: Change from
modules: {
autoRequire: {
"js/app.js": ["web/static/js/app"]
}
}
To
modules: {
autoRequire: {
"js/app.js": ["web/static/js/app"],
"js\\app.js": ["web/static/js/app"]
}
}
This way the app.js is autoRequired, even if you work on a Windows based system.
I would like to mention, that this solution is based on the link Chowza himself posted, so all credit goes to him for pointing to the link.

IE8 issues with Yammer embed and API

Facing multiple issues with IE 8 (detailed version 8.0.7601.17514). Please note everything works fine in other browsers.
Yammer embed my feed control is not working. Sometimes it shows result and sometimes not.
REST API call not working and giving error as below. However I used new js sdk and new yam.platform.request.
Error is : yam.request is null or not an object. source : platform_js_sdk.js
Thanks in advance for your help!
I found out that the div that you embed yammer feed has to be above the yammer request script
eg.
<div id="embedded-feed" style="height:400px;width:500px;"></div>
<script>
yam.connect.embedFeed(
{ container: '#embedded-feed',
network: 'fourleaf.com' // network permalink (see below)
});
</script>
Otherwise, IE will not be able to find the div to show the feed (but chrome works fine..)

Facebook Apps Performance - Insights

How to i know my apps perfomance and page loding ratings in Insights.
i referred App on Facebook tutorial,
through that i used following methods in my code,
FB.Canvas.setDoneLoading , FB.Canvas.Prefetcher.addStaticResource and
FB.Canvas.Prefetcher.setCollectionMode.
My Code:
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({ appId: '*****', cookie: true, xfbml: true, oauth: true });
FB.Canvas.Prefetcher.setCollectionMode(FB.Canvas.Prefetcher.COLLECT_AUTOMATIC);
FB.Canvas.Prefetcher.addStaticResource("http://example.com/fb/js/fb.js");
FB.Canvas.Prefetcher.addStaticResource("http://example.com/fb/css/fb.css");
FB.Canvas.Prefetcher.addStaticResource("http://example.com/fb/css/style.css");
FB.Canvas.setDoneLoading();
};
</script>
<script type="text/javascript" src="//connect.facebook.net/en_US/all.js"></script>
when i see in insight dashboard it showing like,
is there any wrong.. why its not showing... have i call that methods in correct place..?
thanks in advance..
Have you tried the Graph API Explorer to ensure that they're working in that respect?
http://developers.facebook.com/tools/explorer/?method=GET&path=2439131959%2Fstaticresources
Use the dropdown at the top right to select your application (you should be logged in as the owner of the app you want to test); your selection will replace the &path=nnn in the input field to the right of the GET request in the explorer.
Make sure that you're not getting an error response from Facebook. This is how I've checked my prefetch methods; I haven't used the insights dashboard yet.

Resources