HI i am trying to send data using analytics.js but show error.
<head>
<meta charset="utf-8">
<title>GanalaticsDemo</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<form action="">
<label for="gsearch">Search Google:</label>
<input type="search" id="gsearch" name="gsearch">
<input type="submit">
</form>
<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', 'https://www.google-analytics.com/analytics_debug.js', 'ga');
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
var _gaq = _gaq || [];
_gaq.push(["_setAccount", "UA-169197862-1"]);
_gaq.push(["_setDomainName", "none"]);
_gaq.push(["_trackPageview"]);
// window.ga_debug = {trace: true};
ga('create', 'UA-169197862-1', 'auto');// add your tracking ID here.
ga('require','ecommerce','ecommerce.js')
ga('ecommerce:addTransaction',{
'id':'1234',//Transaction id
'affiliation':'skinny jeans',
'revenue':'28.8',
'shipping':'10.00',
'tax':'1.89'
});
ga('ecommerce:addItem',{
'id':'1234',
'name':'OKEJeans',
'sku':'SKJ49',
'category':'Men Jeans',
'price':'76.65',
'quantity':'1'
});
ga('ecommerce.send')
ga('send', 'pageview');
</script>
Contact Sales
</body>
The error in developer tools says : Running command: ga("ecommerce.send");
analytics_debug.js:25 Command ignored. Unknown target: undefined and Running command: ga("send", "pageview")
analytics_debug.js:25 Unallowed document protocol. Aborting hit.
I searched in internet but many said to add targetname but it is also not working.
You are mixing _ga and _gaq code library. The second library is deprecated.
Related
So I am trying to setup a cookie consent banner and trigger Analytics when the user accept the service. This is my second attempt doing this(first time I failed miserable) and I am not sure if I am missing something, because in the research I did, looks pretty much straight forward but for some reason is not working for me.
This is the way my configuration looks on the GTM dashboard. So my Tag manager, where i have for now only two tags, one for the banner, that is a HTML custom Tag and the second that is for the Google Analytics.
This is the way my Custom HTML looks like.
When I try to run the GTM preview mode this is what I get. For me it's not clear, it says the Tag is triggered, however is not displayed on the preview mode, nor on the website
I also need to mention, that I placed the container on the website, and my code looks as follows(for now), also this is a SPA I also don't know if can be something related to that:
<!DOCTYPE html>
<html lang="">
<head>
<script type="text/javascript">
// create dataLayer
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
// set „denied" as default for both ad and analytics storage,
gtag("consent", "default", {
ad_storage: "denied",
analytics_storage: "denied",
wait_for_update: 2000 // milliseconds to wait for update
});
// Enable ads data redaction by default [optional]
gtag("set", "ads_data_redaction", true);
</script>
<!-- Google Tag Manager -->
<script type="text/javascript">(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-XXXXXX');</script>
<!-- End Google Tag Manager -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>
<%= htmlWebpackPlugin.options.title %>
</title>
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX" height="0" width="0"
style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
I am not sure if I need to provide another type of information, so please let me know.
** EDIT **
Below the custom HTML Tag script, where the first script is just to include the main SDK script.
<script>
var cookie = document.createElement("script");
cookie.setAttribute(
"src",
"https://www.mywebsite.com/redesign-scripts/vendor/udg-uc-sdk.min.js"
);
cookie.setAttribute("id", "xxxxxxxx");
document.head.appendChild(cookie);
</script>
<script>
var GlobalConsent = GlobalConsent || {};
//Activate new modal style
GlobalConsent.NewModalSDK = true;
//Set language
GlobalConsent.Language = 'en';
//Set privacy shield content
window.ucPrivacyShield = {
bgimage: 'https://linktoimage.com/image.jpg',
consentunavailable: {
text: 'Die zur Anzeige notwendigen Inhalte konnten nicht geladen werden. Falls Sie einen AdBlocker verwenden, überprüfen Sie bitte dessen Einstellungen.'
},
consentservice: {
headline: 'Hinweis zur Datenverarbeitung',
text: 'Auf unserer Website stellen wir Inhalte von ###SERVICE### bereit. Um diese Inhalte zu sehen, müssen Sie der Datenverarbeitung durch ###SERVICE### zustimmen.',
buttons: {
consent: {
label: 'Zustimmmen'
},
privacy: {
label: 'Hinweise zum Datenschutz',
link: 'https://www.mywebsite.com/de/privacy/'
}
}
}
};
//Wait for UC SDK loading
window.addEventListener('ucReady', function (e) {
//Check Youtube & Vimeo iFrame consent
window.ucPrivacyShield.checkConsent({
mapContainer: document.getElementById('youtube-vimeo-iframe'),
processorId: ['_xxxxx', '-xxxxx'],
timeoutVar: {},
callbacks: {
success: function () {
var iFrame = document.getElementById('youtube-vimeo-iframe').getElementsByTagName('iframe')[0];
iFrame.src = iFrame.dataset.src;
},
p: undefined
}
});
}, false);
</script>
*U P D A T E
I was wondering if someone else have any idea about this, I still don't manage to solve the issue, And I was wondering if it related that the app is rendered client site, and someone when the google tag is trying to append the DOM it is still not there, I tried by wrapping the append inside a "onload" function, but did not worked as well
Did you check localStorage and cookies to ensure, that you don't have preexisting settings.
The banner is only displayed, when there are no preexisting settings in your web storage. Since there are "consents-initialized" dataLayer events displayed in your screenshot, this could be possible.
I've an ecommerce site and I'm tracking the Orders in the Thank-you page sending all the transaction data within the DataLayer variable.
The transaction data is been sent and recorded but I'm getting this error message when debugging with Tag Assitant Chrome Extention:
Event hits must be sent after a pageview hit, but this event hit was
not preceded by a pageview
HTML of Thank-you page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Stickers Gallito Perú">
<meta name="google-site-verification" content="fGkwUY2RcijkVzB6DiwIuAToP1y5xw8ECXQQabRAOIM"/>
<link href="https://fonts.googleapis.com/css?family=Bree+Serif" rel="stylesheet">
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<title>Stickers Gallito</title>
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'eec.purchase',
ecommerce: {
currencyCode: 'PEN',
purchase: {
actionField: {
id: 5,
affiliation: 'Stickers Gallito E-Commerce',
revenue: 250.00,
shipping: 15.00,
coupon: ''
},
products: JSON.parse('[{"id": 5, "sku": "S5", "name": "Stickers cuadrados", "price": "250.00", "size": "3cm x 3cm", "quantity": 1}]')
},
}
});
</script>
<!-- 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-TPXWL88');</script>
<!-- End Google Tag Manager -->
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-TPXWL88"
height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<!-- End Google Tag Manager (noscript) -->
#Rest of HTMl body...
I thought that the DataLayer should be before the Google Analytics code, Am I wrong? Or How should I fix this?
The dataLayer can be filled before the GTM script, but an event is best associated to a yet fired pageview (not mandatory but recommended).
You could associate your e-commerce data to a pageview instead of an event, and remove the part event: 'eec.purchase', to do so.
I am facing a very weird issue with Content Security Policy in Chrome and Firefox.
My meta tags looks as follows:
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* https://* 'unsafe-inline'; script-src 'self' http://* https://* 'unsafe-inline' 'unsafe-eval'" />
These lines are creating problems:
Link tag:
<link href='https://fonts.googleapis.com/css?family=Lato:400,700,900' rel='stylesheet' type='text/css'>
Script tag in body:
<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', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-76462125-1', 'auto');
ga('send', 'pageview');
var dimensionValue = 'SOME_APP_NAME';
ga('set', 'dimension1', dimensionValue);
</script>
Video tag below in my page:
<video controls="controls">
<source src="https://www.youtube.com/embed/OhFel6HTHu8" type="video/mp4" />
</video>
Please tell me what I am missing.
If you check the HTTP response, IdentityServer issues CSP headers. You can configure them by setting the various flags on the CspOptions. It's covered in the docs: https://identityserver.github.io/Documentation/docsv2/advanced/csp.html
I'm looking for some info on how to best manage multiple Google AdWords and other tags. My primary question is how to handle both the regular AdWord tag, the standard AdWords Remarketing tags and one of the custom AdWords Remarketing tags I created - say a 180 day RLSA list tag. Do I need a separate tag call (vars, call to the conversion script and the noscript img tag)? Is there a way to combine?
Also - being an ecommerce site - I see that for AdWords I need to add my sales total to the noscript img tag. But what about to the remarketing one? It has a default value of 1.00, instructions make no mention to change that and the js version doesn't have any fields for it so I assume 1.00 is correct?
I am adding my entire code for the receipt of my store which has GA, standard AdWord and as well as the 180 day RLSA tag (which I assume is valid as the basic Remarketing tag). Docs don't seem to ever address multiple tags unfortunately.
<!-- BEGIN: AdWords -->
<script type="text/javascript">
var google_conversion_id = 1002886276;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "DZAUCPS-jQoQhKmb3gM";
var google_conversion_value = 64.98;
var google_conversion_currency = "USD";
var google_remarketing_only = false;
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/1002886276/?value=64.98¤cy_code=USD&label=DZAUCPS-jQoQhKmb3gM&guid=ON&script=0" />
</div>
</noscript>
<!-- END: AdWords -->
<!-- BEGIN: 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-40148609-3', {
userId: '750fd151-6852-4a35-974d-c99f85f993f3'
});
ga('send', 'pageview', {
'title': 'Receipt'
});
ga('send', 'event', 'Completed Order', {
category: 'Shopping',
revenue: 64.98,
id: 734352106,
total: 64.98,
shipping: 0,
tax: 0,
products: []
});
ga('set', 'ecomm_pagetype': 'purchase');
ga('set', 'ecomm_totalvalue', 64.98);
ga('set', 'ecomm_prodid': [218825388699, 118825388699])
</script>
<!-- END: Analytics -->
<!-- BEGIN: AdWords Remarketing -->
<script type="text/javascript">
var google_conversion_id = 1002886276;
var google_conversion_label = "9NX_CKTrkgoQhKmb3gM";
var google_custom_params = {
ecomm_pagetype: 'purchase',
ecomm_totalvalue: 64.98,
ecomm_prodid: [218825388699, 118825388699]
};
var google_remarketing_only = true;
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/1002886276/?value=1.00¤cy_code=USD&label=9NX_CKTrkgoQhKmb3gM&guid=ON&script=0" />
</div>
</noscript>
<!-- END: AdWords Remarketing-->
Thanks for any assistance or official guides to multiple tag management.
The question is old, yet I came here from Google just before I found an answer to a similar problem, so I'll try to share my conclusions. It is best to integrate Google Tag Manager in case of having multiple codes. I consider it to be the best practice for your example.
One ad unit just stopped to work and after trying to generate new code it is still not working. When I use google console it is just showing warning Ad unit failed to fetch. Other 3 ads are working normally. They are inserted before I started to work on this project.
New ad code is generated like
header
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/6000854/R300x250_L', [300, 250], 'div-gpt-ad-1367703773182-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
body
<!-- R300x250_L -->
<div id='div-gpt-ad-1367703773182-0' style='width:300px; height:250px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1367703773182-0'); });
</script>
</div>
Old code is generated like
header
<script type='text/javascript' src='http://partner.googleadservices.com/gampad/google_service.js'></script>
<script type='text/javascript'>
GS_googleAddAdSenseService("ca-pub-2838961657718357");
GS_googleEnableAllServices();
</script>
<script type='text/javascript'>
GA_googleAddSlot("ca-pub-2838961657718357", "Top728x90");
GA_googleAddSlot("ca-pub-2838961657718357", "Right300x250");
GA_googleAddSlot("ca-pub-2838961657718357", "Right300x250Bottom");
</script>
<script type='text/javascript'>
GA_googleFetchAds();
</script>
body
<!-- Right300x250Bottom -->
<script type='text/javascript'>
GA_googleFillSlot("Right300x250Bottom");
</script>
Is there maybe conflict because of diferent tags or code
NOTE: I am just wordpress front end developer, I don't have access to google DFP services and I am not generating tags or code
EDIT: Based on this discussion it looks like using the old GAM tags with GPT tags may now be an issue (just recently) http://productforums.google.com/forum/#!topic/dfp/snK7znwUMBE
I think you should convert the GAM tags to to GPT tags and use just the DFP GPT tags if possible to stop this happening... its most probably a conflict between the two scripts and depending on the order they get loaded the GPT tags may not work...
ORIGINAL:
I just tried your code and two ads showed as expected. So there does not appear to be any conflicts using both scripts at the same time.
Potentially you have been refreshing the page so many times that there are no ads that will be displaying for you through DFP anymore because of rate limits? That is just a wild guess though. If I refresh the page a lot I do get the failed to fetch message every now and then in the console so I think it is probably just a rate limit and something that a normal user will not have a problem with.
This is the code that I am using, two 300x250 ads show on the page so everything is working correctly.
<html>
<head>
<title>DFP TEST</title>
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/6000854/R300x250_L', [300, 250], 'div-gpt-ad-1367703773182-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<script type='text/javascript' src='http://partner.googleadservices.com/gampad/google_service.js'></script>
<script type='text/javascript'>
GS_googleAddAdSenseService("ca-pub-2838961657718357");
GS_googleEnableAllServices();
</script>
<script type='text/javascript'>
GA_googleAddSlot("ca-pub-2838961657718357", "Top728x90");
GA_googleAddSlot("ca-pub-2838961657718357", "Right300x250");
GA_googleAddSlot("ca-pub-2838961657718357", "Right300x250Bottom");
</script>
<script type='text/javascript'>
GA_googleFetchAds();
</script>
</head>
<body>
<!-- R300x250_L -->
<div id='div-gpt-ad-1367703773182-0' style='width:300px; height:250px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1367703773182-0'); });
</script>
</div>
<!-- Right300x250Bottom -->
<script type='text/javascript'>
GA_googleFillSlot("Right300x250Bottom");
</script>
</body>
</html>