Disabling cookies in Google Analytics - gtag.js - cookies

I am looking for a way to disable the cookies set by Google Analytics.
I found some infos in Google's devguides:
https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#disabling_cookies
Here it says that I should add the following code:
ga('create', 'UA-XXXXXXXXX-X', {
'storage': 'none'
});
But where exactly?
I already tried to add it inside the tracking code:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-X');
ga('create', 'UA-XXXXXXXXX-X', {
'storage': 'none'
});
</script>
I'm grateful for every clue.

Given you use gtag.js (based on your example):
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied'
});
gtag('config', 'xxx');
https://developers.google.com/tag-platform/devguides/consent#set_consent_defaults

storage: 'none' is for analytics.js https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#disabling_cookies
For gtag.js, I think client_storage: 'none' is what you're looking for. It's referenced in a Medium article titled How to use Google Tag Manager and Google Analytics Without Cookies
<!-- Global site tag (gtag.js) - Google Analytics with out cookies -->
<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', {
client_storage: 'none',
client_id: CLIENT_ID,
});
</script>

Two things, you have confused two versions, the ga create and gtag are different versions. Use the gtag one. Your code for this to work is below:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA- XXXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
window['ga-disable-UA-XXXXXXXXX-X'] = true;
gtag('config', 'UA-XXXXXXXXX-X');
});
</script>
See reference here https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out

Related

Code to disable Google Analytics / Adwords cookie until user confirms they accept cookies?

I found this previous question but I was wondering if there are other ways I could delay GA setting the cookies? That code wasn't clear to me at all, so I'm suspicious of it. How sensitive is the analytics code to being tampered with? Google suggests the code needs to be the first thing in the head tag, so I'm wondering if modifications to it would interfere with its functionality?
The code looks like this:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-**********"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-**********');
</script>
The code for Adwords is similar:
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-1068746090"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-1068746090');
</script>
Google suggests the code needs to be the first thing in the head tag, so I'm wondering if modifications to it would interfere with its functionality?
Actually it does not matter where you put the code. The earlier/higher you put it the earlier the browser will load it, execute it and send a pageview.
If you prefer page performance (e.g. web core vitals) over misleading tracking, you can replace the async attribute with a defer attribute which will cause GA to load later (e.g. after your page is "ready").
I prefer deferring GA. For us there is no point in measuring pageviews which bounce even before the page is "ready".
Please take into consideration that if you use both - GA4 and AW - the code would look like
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXX');
gtag('config', 'AW-00');
</script>
You do not include it twice.
There's documentation from Google for Consent Mode and about Privacy
Your code would look like this:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied'
});
gtag('js', new Date());
gtag('config', 'G-XXX');
gtag('config', 'AW-00');
</script>
And here's a brief walkthrough:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXX"></script>
This loads the tracking code/library. Once it is loaded, it will override the dataLayer.push method and process all entries of the dataLayer array (if there are any). If you would only have this line of markup, nothing would happen. No cookies, no tracking.
window.dataLayer = window.dataLayer || [];
This is some precaution. We cannot be sure if the tracking code/library has been loaded and executed (and declared the dataLayer variable), so we check if dataLayer is undefined. If is undefined we initialize it as an empty array.
function gtag(){dataLayer.push(arguments);}
For easier usage and/or branding we wrap the dataLayer.push() method call in a function called gtag. You could use cl22 or timw instead, it would not matter.
gtag('consent', ...
If you would inspect dataLayer now, it would look like this:
[
[
"consent",
"default",
{
"ad_storage": "denied",
"analytics_storage": "denied"
}
]
]
If push method was already overridden by GA4, this would have been already executed. If not it would sit there and wait until GA4 loads.
gtag('js', new Date());
This creates a timestamp.
gtag('config', 'G-XXX');
This will initialize tracking. In default setups, this will send a page_view event. Here GA4 would set its cookies, but because of our previous "entry" it won't.
gtag('config', 'AW-00');
This will initialize AdWords.

How to display PDF in Camunda Embedded form

I have seen many discussions on how to display a PDF file within a embedded form ( User Task ) But realised camunda does not support this. Are there any solutions?
I have tried using IFrame, Object, embed , and directly linking to a variable did not work ?
My solution is to fetch the variable and convert to a blob as follows:
HTML
<embed class="col-sm-12" style="height:100vh;width:100%" type="application/pdf" id="pdf-frame">
JS
<script cam-script type="text/javascript">
camForm.on('form-loaded', function () {
fetch("http://localhost:8181/camunda/api/engine/engine/default/task/" + camForm.taskId + "/variables/ACORD_FORM/data").then(function (response) {
return response.blob();
}).then(function (myBlob) {
var objectURL = URL.createObjectURL(myBlob);
document.querySelector('#pdf-frame').src = '';
document.querySelector('#pdf-frame').src = objectURL;
objectURL = URL.revokeObjectURL(myBlob);
});
});
</script>

Power BI Premium - embed using Power BI API and javascript not working like previous way

Earlier I used to use 'loadReport' from javascript which is not working with new PBI Premium, e.g. the below is not working anymore & it always says "This content isn't available". BTW this is still working for PBI embedded reports.
<html>
<body>
<iframe id="iFrameEmbedReport"></iframe>
</body>
<script type="text/javascript">
window.onload = function () {
var iframe = document.getElementById('iFrameEmbedReport');
iframe.src = 'https://app.powerbi.com/reportEmbed?reportId=******-088f-4967-***-279bd5a**df&groupId=*****-****-4033-862d-1cd4f4fa72c1';
iframe.onload = function()
{
var m = {
action: 'loadReport',
accessToken: 'H4s*****'
};
message = JSON.stringify(m);
iframe = document.getElementById('iFrameEmbedReport');
iframe.contentWindow.postMessage(message, "*");
};
};
</script>
</html>
But if we use powerbi.js with the same configs its working fine (below)
<html>
<body>
<div id="reportContainer"></div>
</body>
<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/jquery/dist/jquery.js"></script>
<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/powerbi-client/dist/powerbi.js"></script>
<script type="text/javascript">
window.onload = function () {
var accessToken = '******************';
var embedUrl = 'https://app.powerbi.com/reportEmbed?reportId=**********&groupId=**********';
var embedReportId = '*****-088f-****-aa2d-279bd5a662df';
var models = window['powerbi-client'].models;
var config = {
type: 'report',
tokenType: models.TokenType.Embed,
accessToken: accessToken,
embedUrl: embedUrl,
id: embedReportId,
permissions: models.Permissions.All,
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true
}
};
var reportContainer = $('#reportContainer')[0];
var report = powerbi.embed(reportContainer, config);
}
</script>
</html>
Not able to figure out what has changed. I really don't want to include powerbi.js in my application if not needed. I know I have a working copy but really need to understand what has changed and if there is any way I can avoid powerbi.js. End goal is to use the first approach in UWP App.
Thanks
The main thing that's changed in the 2 approaches is the property TokenType.Embed which is not available in the 'old way', i.e. 'loadReport' message format.
This is a deprecated way of communicating with embedded entities from Power BI, and all users are encouraged to write their code against the new and maintained Javascript SDK: https://microsoft.github.io/PowerBI-JavaScript/
The 'loadReport' way work for backward compatibility concerns but you won't be able to write new code in new methods using this way.

Integrating Flow JS with Ember JS - Data not Binded

I am trying to integrate FlowJS with EmberJS. I was successful to upload data to server, so, I am good on that part.
I am unsuccessful When trying to bind flow object data with emberJS component to show data via handlebars. For some reason data binding is not working.
Here is an example of the code.
HTML
<script type="text/x-handlebars" data-template-name="index">
{{flow-uploader}}
</script>
<script type="text/x-handlebars" id="components/flow-uploader">
<div class="drop"></div>
<!-- file list -->
{{#each file in flow.files}}
<p>File name: {{file.name}}</p>
{{/each}}
</script>
JS
App = Ember.Application.create({
rootElement: '#main'
});
App.FlowUploaderComponent = Ember.Component.extend({
flow: function(){
return new Flow({
target: 'http://google.com',
testChunks: false
});
}.property(),
initDropZone: function(){
var flow = this.get('flow');
var drop = this.$('.drop')[0];
var $this = this;
flow.assignDrop(drop);
/*flow.on('fileAdded', function(file, flow){
});
flow.on('filesAdded', function(files){
});
flow.on('fileSuccess', function(file,message){
console.log('file success');
});
flow.on('fileError', function(flow, message, chunk){
console.log('file error');
});*/
flow.on('filesSubmitted', function(){
console.log($this.get('flow').files);
//flow.upload();
});
/*flow.on('complete', function(event, flow){
console.log('completed');
});
flow.on('uploadStart', function(event, flow){
console.log('uploading..');
});
flow.on('fileProgress', function(flow, file){
});*/
}.on('didInsertElement')
});
Example can be seen live at http://jsfiddle.net/sisir/qLuobq48/2/
Basically what I am doing here is to save the flow object as component property. files property of flow object is the array of file to be uploaded. Once we drag and drop or select multiple files to upload the files array gets updated. We can see it on the console. The logging code is added via filesSubmitted event.
From the handlebars expression each file is iterated from the files queue. Initially it is empty but later when it gets populated it doesn't show on the html. The data binding is not working for some reason.
In your component logic:
App.FlowUploaderComponent = Ember.Component.extend({
flow: function(){
return new Flow({
target: 'http://google.com',
testChunks: false
});
}.property(),
initDropZone: function(){
var $this = this;
var flow = this.get('flow');
var drop = this.$('.drop')[0];
flow.assignDrop(drop);
flow.on('filesSubmitted', function(){
//for setting a single property
$this.set('flowFiles', flow.files);
//for setting multiple properties
// $this.setProperties({'flowFiles': flow.files, /* etc.. */});
});
}.on('didInsertElement')
});
In your template:
<script type="text/x-handlebars" data-template-name="index">
{{flow-uploader}}
</script>
<script type="text/x-handlebars" id="components/flow-uploader">
<div class="drop"></div>
<!-- file list -->
{{#each file in flowFiles}}
File name: {{file.name}}
{{/each}}
</script>
See JSBin Example
The problem with your JSFiddle simply is(/was) that you referenced a text/plain file as JavaScript. As I asked here, not every file is usable in JSFiddle and GitHub does not like to get misused as pseudo-CDN for lazy people.
In other words: This error
Uncaught ReferenceError: Flow is not defined
is a result of this error
Refused to execute script from 'https://raw.githubusercontent.com/flowjs/flow.js/master/dist/flow.min.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
and can be fixed using
https://rawgithub.com
or the MaxCDN version
http://rawgit.com/
in place of the branch file URl.
Look at the new JSFiddle with all the console.log() statements. The files added, file added and submitted logs in the console are telling me that everything in your code works fine once you got the right file in use. PROTip: Always check your console for errors.

can't publish built-in actions via facebook app

Hi I have been dealing with facebook apps and actions a lot lately and it doesn't seem to work for me. Now I hear that the social button for likes is about to migrate and I can't figure out how to even publish the like built-in action via the app I created (it's an app for websites).
The code to publish actions I have taken from here: https://developers.facebook.com/docs/opengraph/tutorial/ and this is what they say:
<head prefix="og: http://ogp.me/ns# [YOUR_APP_NAMESPACE]:
http://ogp.me/ns/apps/[YOUR_APP_NAMESPACE]#">
<title>OG Tutorial App</title>
<meta property="fb:app_id" content="[YOUR_APP_ID]" />
<meta property="og:type" content="[YOUR_APP_NAMESPACE]:recipe" />
<meta property="og:title" content="Stuffed Cookies" />
<meta property="og:image" content="http://fbwerks.com:8000/zhen/cookie.jpg" />
other metatag properties etc.
<script type="text/javascript">
function postCook()
{
FB.api(
'/me/[YOUR_APP_NAMESPACE]:cook',
'post',
{ recipe: 'http://fbwerks.com:8000/zhen/cookie.html' },
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
}
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '[YOUR_APP_ID]', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
etc etc.
<form>
<input type="button" value="Cook" onclick="postCook()" />
</form>
<fb:activity actions="[YOUR_APP_NAMESPACE]:cook"></fb:activity>
the fact is that I am not able to publish any action (returns an error) and of course my app has the actions I am trying to publish. Doesn anyone have a clue? I'm not a professional developer but the ones I asked had no solution...
Many thanks!
I found the problem!
Apparently the include function in PHP had the headed we used around the website conflict with the Facebook metadata. When I removed the headers and the "php start", all functions (comments included) were working.
It still seem a peculiar issue though: apparently Facebook's API doesn't clear the cache, so now we have to create new pages to enable functions. No way to have them in the current page locations.