MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff) - google GTM 400 error - mime-types

I am trying to solve error from firefox console:
The resource from
“https://googleads.g.doubleclick.net/pagead/viewthroughconversion/973891309/?random=1655454537427&cv=9&fst=1655454537427&num=1&guid=ON&resp=GooglemKTybQhCsO&eid=375603261&u_h=1080&u_w=1920&u_ah=1040&u_aw=1920&u_cd=24&u_his=5&u_tz=120&u_java=false&u_nplug=0&u_nmime=0&sendb=1&ig=1&frm=0&url=https%3A%2F%2Fwww.gm.gama-sklep.com.pl%2F&tiba=Meble%20-%20Internetowy%20Sklep%20Meblowy%20Gama&hn=www.googleadservices.com&rfmt=3&fmt=4”
was blocked due to MIME type (“text/plain”) mismatch
(X-Content-Type-Options: nosniff).
In previous topics on this forum usually problem was with script url and type but in this situation above url is called from google tag manager script which is delivered from google. Base script is typical for gtm and looks like this:
<!-- 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', 'GTM-NXQN6F4');
</script>
<!-- End Google Tag Manager -->
Similar situation is when i try to add remarketing tag without gtm using js code from ads panel:
<!-- Global site tag (gtag.js) - Google Ads: 482376610 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-482376610"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-482376610');
</script>
Above code will also report 400 error + mime type error.
Is this a problem releated to server?

Related

Window.ga is undefined in Firefox when using Google Tag Manager in React

I have a standard React project and am using Google Tag Manager to load analytics on the page. I have the Google Tag Manager in the head of the index.html. I have some code to retrieve the clientId from the window.ga object and then populate it into a field in my state on one of my components called "gaClientId". I have a method that retrieves the clientId and gets called in componentDidMount(). This works as expected in Chrome and IE but not Firefox for some odd reason. Not exactly sure what the issue is. I have checked to make sure that firefox is not blocking the tracker and have noticed in the console that if I console.log(window.ga) I get the undefined message before Google Tag Manager loads. Didn't know if that is where the issue is. Here is my method:
getGAClientId() {
try {
const tracker = ga.getAll()[0];
let clientId = tracker.get("clientId");
this.setState({ gaClientId: clientId });
} catch (e) {
return null;
}
}
and here is my state in the component:
this.state = {
firstname: '',
lastname: '',
email: '',
gaClientId: ''
};
This is being set to the value of a hidden form field like this:
<input type="hidden" value="this.state.gaClientId" name="gaClientId" />
Here is the head of my index.html just to show you:
<head>
<!-- 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", "GTM-xxxxxxx");
</script>
<!-- End Google Tag Manager -->
</head>
Any help with this is appreciated. Thanks!
Figured it out! I needed to add a setTimeout() to my getGaClientId() call in my componentDidMount. I just updated the code to the below to fix it.
componentDidMount() {
setTimeout(() => {
this.getGAClientId();
}, 2000);
}
I guess the load order of when Google Analytics was loading to when my method was being called was off.

Media.net ads integration with SPA(angularjs)

How to integrate media.net ads in SPA(angularjs) website. I have copied and posted the given code in my website but it is not working(http://test.website.paperboy.com/).
<script id="mNCC" language="javascript">
medianet_width = "728";
medianet_height = "90";
medianet_crid = "xyz";
medianet_versionId = "xyz";
</script>
<script src="//contextual.media.net/nmedianet.js?cid=xyz"></script>
But it is working for non angular static site(https://test.website.paperboy.com/mobile-view.html).
I cannot speak for angularjs, but Angular 2 and beyond scrubs out script tags. Here is the solution for Angular 8. Note this is for the asynchronous ad code, not the synchronous code posted, but the methodology should be the same in which we are adding a DOM element:
.ts file:
convertToScript() {
var element = this.script.nativeElement;
var script = document.createElement('script');
script.id = 'mNCC';
script.lang = this.language ? this.language : 'javascript';
script.type = this.type ? this.type : 'text/javascript';
script.innerHTML = `
try {
window._mNHandle.queue.push(function (){
window._mNDetails.loadTag(${this.advertisement});
});
}
catch (error) {}`;
script['data-cfasync'] = 'false';
const parent = element.parentElement;
parent.parentElement.replaceChild(script, parent);
}
ngAfterViewInit() {
this.convertToScript();
}
.html file:
<div #script style.display="none">
<ng-content></ng-content>
</div>
Add the component where you want (inject the advertisement size and id here)
<div id="616415456">
<app-media-net-ad [type]="'text/javascript'" [advertisement]="advertisement">
</app-media-net-ad>
</div>
The advertisement variable should be formated as "ad_id,ad_size,ad_id". The header code can be added into the header section of your index.html file.

emails from gmail but response is gmail.readonly

I am trying to get the emails from gmail using https://www.googleapis.com/auth/gmail.readonly/?access_token='fdrt654vfdgfe6545But in response I am getting gmail.readonlyBut the System.HttpResponse[Status=OK, StatusCode=200] is fine. Can any guide me is there anything I am missing out.
This I how I requested got auth but in the response I received access token
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
var AuthStates = {google: null};
function signinCallback(authResult) {
if (authResult['status']['signed_in']) {
// Update the app to reflect a signed in user
// Hide the sign-in button now that the user is authorized, for example:
document.getElementById('signinButton').setAttribute('style', 'display: none');
//alert(authResult['code']);
console.log('code state: ' + authResult['code']);
//console.log('authResult : ' + authResult[]);
AuthStates.google = authResult;
console.log('authResult 1 : ' + authResult['status']['method']);
console.log('auth Result : ' + authResult['id_token']);
//{!access_token} = authResult['access_token'];
//{!code} = authResult['code'];
connection(authResult['access_token'], authResult['code']);
} else {
// Update the app to reflect a signed out user
// Possible error values:
// "user_signed_out" - User is signed-out
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatically log in the user
console.log('Sign-in state: ' + authResult['error']);
}
}
</script>
<apex:outputPanel >
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="clientid"
data-cookiepolicy="single_host_origin"
data-scope="https://www.googleapis.com/auth/gmail.readonly"
data-response_type="code"
data-redirect_uri="http://test-on.ap1.visual.force.com/apex/Gmail_inbox">
</span>
</span>
<apex:form >
So as i got my access token from my request I can go directly for getting all information related to the logedin user. As I am getting all the information regarding the user I am trying to get all the emails related to him. Is I am doing right or I am wrong any place. I am very new with api and web service trying to learn. please do help me put out.
You're actually making an HTTP GET call to that URL ( https://www.googleapis.com/auth/gmail.readonly/?access_token= ...)? Isn't that just the auth scope identifier?
Once you have a valid Oauth2 token you can set in the Auth header then you can make HTTP requests to the API. For example, to list messages see:
https://developers.google.com/gmail/api/v1/reference/users/messages/list
That has the URL to access (GET https://www.googleapis.com/gmail/v1/users/me/messages ) then once you have the message IDs you can get the messages individually following: https://developers.google.com/gmail/api/v1/reference/users/messages/get (e.g. GET https://www.googleapis.com/gmail/v1/users/me/messages/ ).
Usually there are good client libraries for the Google APIs. Not sure if that works for you, but see, for example:
https://developers.google.com/gmail/api/downloads

channel in trivial GAE app not getting 'onmessage'

I am trying to create the smallest possible GAE app to show the use of the channel api.
I have two handlers in the python, the first "TestPage" sends out the html shown below. The second "SendPage" tries to send a message over the channel to the test page. The code for the TestPage is
class TestPage(Handler):
def get(self):
token = channel.create_channel("1")
self.render("test.html", token = token)
It just creates the channel with an id of "1" and reders the page with the token passed back from create_channel().
The SendPage is just:
class SendPage(Handler):
def get(self):
channel.send_message("1", "hello")
self.write("sent hello to 1")
The html is as small as I could get it:
<!DOCTYPE HTML>
<html>
<body>
<br>Token is {{ token }}
<br>
<div id="debug">_</div>
<!--
<script src="https://talkgadget.google.com/talkgadget/channel.js"></script>
-->
<script src="static/channel.js"></script>
<script defer="defer">
function debug(s) {
document.getElementById("debug").innerHTML = s;
}
var channel = new goog.appengine.Channel( {{ token }} );
var socket = channel.open();
socket.onopen = function(e) {
debug("open");
}
socket.onclose = function(e) {
debug("close");
}
socket.onerror = function(e) {
debug("error");
}
socket.onmessage = function(e) {
debug("message");
}
debug("ready");
</script>
</body>
</html>
So, inside chrome I pull up TestPage and I see the "ready" message. Then I pull up the SendPage in another tab. And see the "sent message". Then when I go back to the TestPage I would expect to have "ready" replaced by "message". But this never happens. None of the socket handler functions are being called.
I'm stuck for the moment and would appreciate any help or suggestions.
Thank you.
Ok, I figured it out. There were two problems. First, the template line
var channel = new goog.appengine.Channel( {{ token }} );
should have been
var channel = new goog.appengine.Channel( "{{token}}" );
as it was token was something like "channel-2052893164-1373347311-1" which quietly evaluated to a number.
Second, the correct script for the channel.js was
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
The other scripts I had referenced were from other stack overflow answers and I guess they did not properly apply to this problem.
Thanks.

how to track the user timings( start time and end time) for Silverlight application using google analytics...?

I have recently signed-up at Google Analytics and also new to same.
I want to track the button click and user start time and end time using google analytics.
I have also received following javascript from Google analytics:
<script type="text/javascript">
(
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-########-1', 'blahblah.com');
ga('send', 'pageview');
</script>
I know how to call javascript function from .net application, but how to deal with user timings, I have also refered the link
https://developers.google.com/analytics/devguides/collection/analyticsjs/user-timings
but didn't found helpful/fruitful.
Please help soon, your early response is highly appreciated.
Thanks,
Vijay.
You may use Event Tracking with value. Start a timer when silverlight loaded or with a click button and you need to send the total time when you decide it's the end;
_gaq.push(['_trackEvent', 'User Actions', 'Session Duration', 'Tom Hanks', 49.9, true]);
you may either create custom reports for each user or default event reports for averages.

Resources