Deleting Google Analytics cookies on server
We have been trying to remove the Cookies that GTM creates when we specify that the user don't want them enabled.
We load GTM the first thing of the header, then the JS Cookies library and finally our following code.
// Loaded page
window.dataLayer = window.dataLayer || [];
function gtag(){
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'XX-XXXXXXXX-X');
if (cookiesEnabled) { // a variable that shows if they are enabled
// Cookies accepted
window['ga-disable-XX-XXXXXXXX-X'] = false
} else {
window['ga-disable-XX-XXXXXXXX-X'] = true
}
// Function to set the cookies
function setCookies (accepted) {
if (!accepted) {
Cookies.set('_ga', undefined, {
expires: -1,
path: '', // Also tested with /
domain: `.${document.domain}`
})
Cookies.set('_gid', undefined, {
expires: -1,
path: '', // Also tested with /
domain: `.${document.domain}`
})
Cookies.set('_gat_gtag_XX_XXXXXXXX_X', undefined, {
expires: -1,
path: '', // Also tested with /
domain: `.${document.domain}`
})
// This was also tested
Cookies.remove('_ga', {
path: '', // Also tested with /
domain: `.${document.domain}`
})
Cookies.remove('_gid', {
path: '', // Also tested with /
domain: `.${document.domain}`
})
Cookies.remove('_gat_gtag_XX_XXXXXXXX_X', {
path: '', // Also tested with /
domain: `.${document.domain}`
})
}
}
We have tried this on both ways, with set and remove. The code running on our local machine works perfectly, the cookies are being removed without any problem, but then, when we pass the exact same code to our test server, those cookies will not be removed.
There is something that maybe we are missing? We were unable to find what.
do you know?
how many words do you know
See also questions close to this topic
-
how to change prettier format for react native
my code formatting prettier didn't works well for react native, i don't understand where to config it but it works well with flutter
from this code
import { View, Text } from 'react-native' import React from 'react' export default function App() { return ( <View> <Text>Apps</Text> </View> ) }
it's formatted to this
import { View, Text } from 'react-native' import React from 'react' export default function App() { return ( < View > < Text > Apps < /Text> < /View> ) }
-
MarkLogic server-side JavaScript and XQuery
I am just starting using NoSQL MarkLogic DB and trying to choose for me the best query language to learn and use in future. On server side MarkLogic provides the possibility to use JavaScript API or XQuery API.
I want to receive an advice. Which language is better to concentrate on and learn? JavaScript or XQuery?
- Popover in chrome extension using js
-
Hosting frontend and backend on two different Heroku domains
I made a full-stack web application with React and Express as part of my portfolio projects. I tried publishing it on Vercel and Heroku (tried Netlify also) but unfortunately, I learned that sending cookies between two different domains is not possible. The next thing I tried, is to host both on Heroku (e.g:
client.herokuapp.com
&server.herokuapp.com
) which, unfortunately, does not work also.What else do I need to do? I am still learning how to deploy properly so I might miss out on some workarounds. Advice is greatly appreciated.
-
How to clear a cookie in Lucee
How to clear a cookie in Lucee
I have a code in ACF as below, below code not working it gives blank page.
<cfheader name="Set-Cookie" value="bouluser=;expires=#DateFormat(CreateDate(1970,1,1), 'ddd, dd-mmm-yyyy')# #TimeFormat(CreateTime(00,00,00), 'HH:mm:ss')# GMT;path=/;"> <cfheader name="Set-Cookie" value="bouluser=;expires=#DateFormat(CreateDate(1970,1,1), 'ddd, dd-mmm-yyyy')# #TimeFormat(CreateTime(00,00,00), 'HH:mm:ss')# GMT;domain=.boul.com;path=/;"> <cfheader name="Set-Cookie" value="bouluser=;expires=#DateFormat(CreateDate(1970,1,1), 'ddd, dd-mmm-yyyy')# #TimeFormat(CreateTime(00,00,00), 'HH:mm:ss')# GMT;domain=boul.com;path=/;">
Getting below error some times: Generic Connector Communication Error: Please check and adjust your setup: Ensure that Tomcat is running on given host and port. If this is a timeout error consider adjusting IIS timeout by changing executionTimeout attribute in web.config (see manual). [2022-05-06 22:38:44 ]
-
Yahoo Finance no longer returns VBA cookie request for .getResponseHeader("Set-Cookie")
The following Excel VBA code segment has worked for years, but stopped working around 28 Apr 2022. I receive the responseText, but the .getResponseHeader("Set-Cookie") returns null.
Set httpReq = New WinHttp.WinHttpRequest DownloadURL = "https://finance.yahoo.com/lookup?s=" & stockSymbol With httpReq .Open "GET", DownloadURL, False .setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" .Send .waitForResponse response = .responseText cookie = Split(.getResponseHeader("Set-Cookie"), ";")(0) End With
-
How would you capture a discount that covers the cost of taxes with GA4 Purchase parameters?
Would I add a data layer variable for the purchase event outside of the items array? This is Google's recommendation for purchase events. I want to add a coupon code with a discount that covers the entire cost including taxes. This is what google has in their doc:
dataLayer.push({ event: "purchase", ecommerce: { transaction_id: "T_12345", affiliation: "Google Merchandise Store", value: 25.42, tax: 4.90, shipping: 0, currency: "USD", coupon: "SUMMER_SALE", items: [ { item_id: "SKU_12345", item_name: "Stan and Friends Tee", affiliation: "Google Merchandise Store", coupon: "SUMMER_FUN", currency: "USD", discount: 2.22, index: 0, item_brand: "Google", item_category: "Apparel", item_category2: "Adult", item_category3: "Shirts", item_category4: "Crew", item_category5: "Short sleeve", item_list_id: "related_products", item_list_name: "Related Products", item_variant: "green", location_id: "L_12345", price: 9.99, quantity: 1 }] } });
I want to create a cart that gives the user for free. Or rather a $0 cart value. Would I add the coupon discount ($4.90 = value + tax) for the whole cart like this:
dataLayer.push({ event: "purchase", ecommerce: { transaction_id: "T_12345", affiliation: "Google Merchandise Store", value: 0, tax: 4.90, shipping: 0, currency: "USD", coupon: "SUMMER_SALE", discount: 4.90, items: [ { item_id: "SKU_12345", item_name: "Stan and Friends Tee", affiliation: "Google Merchandise Store", coupon: "SUMMER_FUN", currency: "USD", discount: 9.99, index: 0, item_brand: "Google", item_category: "Apparel", item_category2: "Adult", item_category3: "Shirts", item_category4: "Crew", item_category5: "Short sleeve", item_list_id: "related_products", item_list_name: "Related Products", item_variant: "green", location_id: "L_12345", price: 9.99, quantity: 1 }] } });
Or would the discount amount including tax ($14.69 = intended discount for product + cost of tax) also be included in the discount for the item in the items array.
dataLayer.push({ event: "purchase", ecommerce: { transaction_id: "T_12345", affiliation: "Google Merchandise Store", value: 0, tax: 4.90, shipping: 0, currency: "USD", coupon: "SUMMER_SALE", discount: 4.90, items: [ { item_id: "SKU_12345", item_name: "Stan and Friends Tee", affiliation: "Google Merchandise Store", coupon: "SUMMER_FUN", currency: "USD", discount: 14.69, index: 0, item_brand: "Google", item_category: "Apparel", item_category2: "Adult", item_category3: "Shirts", item_category4: "Crew", item_category5: "Short sleeve", item_list_id: "related_products", item_list_name: "Related Products", item_variant: "green", location_id: "L_12345", price: 9.99, quantity: 1 }] } });
This is the doc from google that I've been referencing.
Thanks for your help!
-
Adding an custom event to GTM Vimeo event tracking
I'm using this script to push play/pause/progress of vimeo videos on our website. I'd like to push another event "load" when video is loaded on page. I've tried adding a part to send info to the data layer when the video is ready as such:
function onReady(data) { try{ //push to data layer load dataLayer.push({ event: "video", video_action: "load", video_url: 'https://vimeo.com/' + getLabel(data.player_id), video_percent: data.data.percent.toFixed(2) * 100, video_title: _playerTitle[getLabel(data.player_id)].toLowerCase() }); } catch(err){ } }
Here is the full script which pushes the rest of the data sucessfuly.
<!-- Google Analytics Tag Manager (V2) custom HTML tag for Vimeo video tracking Copyright 2016, Cardinal Path, Inc. Original author: Bill Tripple <btripple@cardinalpath.com> Revised by: Bogdan Bistriceanu <bbistriceanu@cardinalpath.com> Version 2.0 --> <script> var dataLayer = (typeof(dataLayer) !== "undefined" && dataLayer instanceof Array) ? dataLayer : []; var videoLabels=[]; var lastP=[]; //we declare variables that will hold information about the video being played var _playerTitle = {}, _playerAuthor = {}, _playerAuthorURL = {}, _playerUploadDate = {}; try{ init(); } catch(err){ dataLayer.push({ 'event': 'gtm.error', 'errorMessage': e.message, 'tag': 'CP - UA - Vimeo Video Listener' }) } function init(){ try{ var player=document.getElementsByTagName("iframe"); for (i = 0; i < player.length; ++i) { var url=player[i].getAttribute("src"); if(/player\.vimeo\.com\/video/.test(url)){ // vimeo iframe found if(!player[i].hasAttribute("id")){ // id attribute missing player[i].setAttribute("id","vimeo_id_"+i); // add id attribute } var urlUpdated=false; if(!/api=/.test(url)){ // check to see if api parameter is in src attribute url=updateUrl(url,"api",1); urlUpdated=true; } if(!/player_id=/.test(url)){ // check if player_id is in src attribute url=updateUrl(url,"player_id",player[i].getAttribute("id")); urlUpdated=true; } if(urlUpdated){ // repopulate src attribute with added parameters player[i].setAttribute("src",url) } videoLabels[player[i].getAttribute("id")]=player[i].getAttribute("src"); // id to label dictionary } } // Listen for messages from the player if (window.addEventListener){ window.addEventListener('message', onMessageReceived, false); } else { window.attachEvent('onmessage', onMessageReceived, false); } } catch(err){ } } function updateUrl(url,param,value){ try{ return url+((/\?/.test(url)) ? "&" : "?")+param+"="+value; } catch(err){ } } // Handle messages received from the player function onMessageReceived(e) { try{ var data = e.data; if(typeof data === "string"){ data = JSON.parse(data); } switch (data.event) { case 'ready': onReady(data); break; case 'play': onPlay(data); break; case 'pause': onPause(data); break; case 'playProgress': onPlayProgress(data); break; } } catch(err){ } } // Helper function for sending a message to the player function post(action, value) { try{ var data = { method: action }; if (value) { data.value = value; } var message = JSON.stringify(data); var player = document.getElementsByTagName("iframe"); var url; var prot; for (i = 0; i < player.length; ++i) { url=player[i].getAttribute("src"); if(/player\.vimeo\.com\/video/.test(url)){ // Check if protocol exists prot = player[i].getAttribute('src').split('?')[0].split('//')[0]; // If protocol doesn't exist, then need to append to "url" if (!prot){ url="https:" + player[i].getAttribute("src").split('?')[0]; } player[i].contentWindow.postMessage(data, url); } } } catch(err){ } } function getLabel(id){ try{ return videoLabels[id].split('?')[0].split('/').pop(); } catch(err){ } } //our function that will use the Vimeo oEmbed API to retrieve additional information about the video function getVimeoInfo(url, callback) { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; document.getElementsByTagName('body')[0].appendChild(script); } //the callback function which takes the data received from the Vimeo oEmbed API and places it into the corresponding objectes function vimeoCallback(e){ //console.log(e); _playerTitle[e['video_id']] = e['title']; _playerAuthor[e['video_id']] = e['author_name'] _playerAuthorURL[e['video_id']] = e['author_url'] _playerUploadDate[e['video_id']] = e['upload_date'] } function onReady(data) { try{ //execute our function which queries the Vimeo oEmbed API once the embedded videos are "ready" getVimeoInfo("https://www.vimeo.com/api/oembed.json?url=https://vimeo.com/"+getLabel(data.player_id)+"&callback=vimeoCallback", vimeoCallback); post('addEventListener', 'play'); post('addEventListener', 'pause'); post('addEventListener', 'finish'); post('addEventListener', 'playProgress'); } catch(err){ } } function onPlay(data){ try{ dataLayer.push({ event: "vimeo", eventCategory: "vimeo", eventAction: "vimeo play", eventLabel: _playerTitle[getLabel(data.player_id)].toLowerCase() + " - " + getLabel(data.player_id), vimeo_playerID: getLabel(data.player_id), vimeo_playerTitle: _playerTitle[getLabel(data.player_id)].toLowerCase(), vimeo_playerAuthor: _playerAuthor[getLabel(data.player_id)].toLowerCase(), vimeo_playerAuthorURL: _playerAuthorURL[getLabel(data.player_id)].toLowerCase(), vimeo_playerUploadDate: _playerUploadDate[getLabel(data.player_id)], nonInteractive: true }); } catch(err){ } } function onPause(data){ try{ dataLayer.push({ event: "vimeo", eventCategory: "vimeo", eventAction: "vimeo video pause", eventLabel: _playerTitle[getLabel(data.player_id)].toLowerCase() + " - " + getLabel(data.player_id), vimeo_playerID: getLabel(data.player_id), vimeo_playerTitle: _playerTitle[getLabel(data.player_id)].toLowerCase(), vimeo_playerAuthor: _playerAuthor[getLabel(data.player_id)].toLowerCase(), vimeo_playerAuthorURL: _playerAuthorURL[getLabel(data.player_id)].toLowerCase(), vimeo_playerUploadDate: _playerUploadDate[getLabel(data.player_id)], nonInteractive: true }); } catch(err){ } } // Track progress: 25%, 50%, 75%, 100% function onPlayProgress(data) { try{ var t = data.data.duration - data.data.seconds <= 1.5 ? 1 : (Math.floor(data.data.seconds / data.data.duration * 4) / 4).toFixed(2); if (!lastP[data.player_id] || t > lastP[data.player_id]) { lastP[data.player_id]=t; if (parseFloat(t) != 0){ dataLayer.push({ event: "vimeo", eventCategory: "vimeo", eventAction: "vimeo video " +t*100+ "% Complete", eventLabel: _playerTitle[getLabel(data.player_id)].toLowerCase() + " - " + getLabel(data.player_id), vimeo_playerID: getLabel(data.player_id), vimeo_playerTitle: _playerTitle[getLabel(data.player_id)].toLowerCase(), vimeo_playerAuthor: _playerAuthor[getLabel(data.player_id)].toLowerCase(), vimeo_playerAuthorURL: _playerAuthorURL[getLabel(data.player_id)].toLowerCase(), vimeo_playerUploadDate: _playerUploadDate[getLabel(data.player_id)], nonInteractive: true }) } } } catch(err){ } } </script>
-
Automating Google Analytics Data into Google Sheets
I want to automate a report where we want to add 200 rows of data into a spreadsheet, the data in these 200 rows comes from Google Analytics with each row having different filters, views etc. Please tell me how to do it?
-
SNP_SESSION Table shows value null in ERROR_MESSAGE column
I tried fetching error message from the snp_session table in ODI 12C. I have explicitly inserted erroneous data in order to get an error. But that error is not showing in the error_message column in snp_session table forthe corresponding session id. Please help
-
Efficient way to erase and re create a (part of, if possible) subplot inside loop using matplotlib?
The code below creates a Scatter plot from
X
and based on values ofw,b
, creates lines over X.I have tried a couple of combinations such as:
fig.canvas.draw() fig.canvas.flush_events() plt.clf plt.cla
But they either seem to plot multiple lines over the plot or Delete the figure / axes.
Is it possible to plot the Scatter plot only once but the Lines keep changing based on
w,b
?.Below is the code that I have used:
from sklearn import datasets import matplotlib.pyplot as plt import numpy as np import time from IPython.display import display, clear_output def get_hyperplane_value(x, w, b, offset): ''' Generate Hyperplane for the plot ''' return (-w[0] * x + b + offset) / w[1] def plot_now(ax, W,b): ''' Visualise the results ''' x0_1 = np.amin(X[:, 0]) x0_2 = np.amax(X[:, 0]) x1_1 = get_hyperplane_value(x0_1, W, b, 0) x1_2 = get_hyperplane_value(x0_2, W, b, 0) x1_1_m = get_hyperplane_value(x0_1, W, b, -1) x1_2_m = get_hyperplane_value(x0_2, W, b, -1) x1_1_p = get_hyperplane_value(x0_1, W, b, 1) x1_2_p = get_hyperplane_value(x0_2, W, b, 1) ax.plot([x0_1, x0_2], [x1_1, x1_2], "y--") ax.plot([x0_1, x0_2], [x1_1_m, x1_2_m], "k") ax.plot([x0_1, x0_2], [x1_1_p, x1_2_p], "k") x1_min = np.amin(X[:, 1]) x1_max = np.amax(X[:, 1]) ax.set_ylim([x1_min - 3, x1_max + 3]) ax.scatter(X[:, 0], X[:, 1], marker="o", c = y) return ax X, y = datasets.make_blobs(n_samples=50, n_features=2, centers=2, cluster_std=1.05, random_state=40) y = np.where(y == 0, -1, 1) fig = plt.figure(figsize = (7,7)) ax = fig.add_subplot(1, 1, 1) for i in range(50): W = np.random.randn(2) b = np.random.randn() ax.cla() ax = plot_now(ax, W, b) display(fig) clear_output(wait = True) plt.pause(0.25)
-
Custom metric/dimension not visible in GA4 DebugView on item/product-list level
We're trying to configure GA4 to gather same data that we have in UA.
The problem is that we cant see custom metrics data on item-level in DebugView. In TagAssistant we can see that data is sent:
{ event: "purchase", gtm: {uniqueEventId: 10, start: 1651XXX}, gtag: { targets: { G-XXX: {_ee: true, _uei: 3, _upi: 2}, UA-XXX: { currency: "PLN", country: "PL", custom_map: { dimension2: "referrer", ... dimension13: "ecomm_totalvalue", metric1: "metric1", ... metric5: "metric5" }, _uei: 4 }, AW-106XXX: {} } }, eventModel: { transaction_id: "40XXX", affiliation: "XXX", value: "9.99", currency: "PLN", tax: "1.87", shipping: "0", coupon: "", items: [ { id: "670", name: "Tusz Zamiennik T0711 do Epson (C13T07114010) (Czarny)", brand: "XXX", category: "Wkłady/Atramentowe/Zamienniki/Tusze/XXX -> Do:E" + "pson", quantity: 1, price: "9.99", coupon: "", metric1: "9.99", metric2: "9.99", metric3: "9.99", metric4: "9.99", metric5: "9.99" } ], send_to: "" } }
However, on DebugView side we can see purchase event that:
- contains all orginal parameters on event level (like transaction_id, shipping etc.)
- contains all orginal parameters on item level (like item_id, quantity, etc.)
But our custom metrics are missing
In the other hand, we tried (with different event) push some custom-dumension data and:
- they are visible on GA4 DebugView
- we can create custom dimension in GA4 basing on this data and it works
I am thinking about:
- Creating event-level custom metric to test if it will be passed to GA4 DebugView
- Creating item-level custom dimension to test if it will be passed to GA4 DebugView
However, due to fact that GA requires 24h to make conclusions i decided to ask here for any sugestions why it is not working and what else may i test.
-
Is there a way to capture video progress for videos in a playlist?
I am trying to capture video plays and progress through GTM. The code works for videos that are not in a video-player. For video-player objects, video plays work for every video, but video progress only fires once per video in the player. Each video has a unique data-video-id but that does not show up in the website until someone has clicked on that particular video. Has anyone run into this before? or have any ideas on how to fix this?
This is the code that is implemented in GTM. https://gist.github.com/alfhh/5ab99138e40800283cecd279037e5f06
-
Keeping user properties between events (Google Tag Manager, Google Analytics 4)
I have a question about user properties in Google Analytics 4.
I created 2 events:
The first one is called custom_session_start and it is triggered every time new session started.
The second is called UI_Interaction which is event that triggers every time that the user is clicking on something in the website.The custom_session_start has some user properties and event parameters his specific tag in GTM. The UI_Interaction event has only event parameters in his specific Tag.
From what I know the user property should be save unless I change it manually, so if I created some user properties in custom_session_start they also should be appear in UI_Interaction.
However, when I create a report in GA4 the user properties are only set in every custom_session_start event and they are empty in UI_Interaction event.Is there a way to keep them also when the UI_Interaction occurs?