I am trying to remove Personally Identifiable Information (PII) from URLs in out Single Page Application (SPA) registered by Google Tag Manager.
The URLs have the form /customer/1234/invoice/5678, which I want to send to GA4 as /customer/(redacted)/invoice/(redacted)
What I did is the following:
In GTM, I created a Custom JavaScript variable called Page location without ids with the following content. (Note: using {{Page URL}} here, but also tried window.location.href with same effect.)
function() {
// including timestamp for debugging purposes
var url = Date.now() + {{Page URL}}.replace(/\d{4}/g, '(redacted)');
// outputting to console for debugging purposes
console.log(url);
return url;
}
In the GA4 configuration tag (which is fired on All Pages), I opened Fields to set and changed the field name page_location to {{Page location without ids}}.
I started Preview in GTM, and let GTM load the website. Tag Assistant comes up on the page, GTM reports it is connected.
Everything seems well so far:
I open the developer console on the website, and see some 20 output lines of the start page URL with timestamp, generated by my GTM script.
In GTM's Tag Assistant I can see the modified URL in both the GTM and GA4 containers, under Variables. (In the GTM container assigned to Page location without ids, in the GA4 container assigned to dl (Page Location).
In GA4, I can see the modified URL in DebugView, assigned to the page_location Parameter.
However, when I navigate to a page with ids in the URL:
The console outputs the redacted URL, good. (4 times actually, don't know why.)
However, the payload of the collect call shows the (redacted) starting page URL for the dl parameter. The actual page URL (redacted or not) is not included.
GTM show a History event logged by the GTM container with the redacted URL in the Page location without ids variable, good. The Page Path and Page URL variables however are not redacted, don't know if this is good or bad.
GTM shows for the GA4 container a Page View with the (redacted) starting page URL for the dl (Page Location) parameter!
And also GA4 in DebugView shows the starting page URL as page_location parameter.
So for some reason I am unable to push the redacted URL into the dl parameter for GA4, instead GA4 keeps on using the redacted initial (starting page) URL.
Well, no, no need really. GA4 configuration+pageview tag only needs to be called once. After that, it starts watching history changes and tracks every pageview on most SPAs. You need to only use the real page view trigger and only add more if your SPA doesn't issue history changes on navigations. But vast majority of SPA engines don't make that mistake anymore.
You should actually try implementing it and then ask your question. Update your question when you encounter non-theoretical issues and we'll help.
Related
I have a "short URL" MVC website that takes in an identifier and redirects the user to the end resource based on that identifier.
Prior to the redirect I create a web request to Google Analytics (GA) to track which identifiers are commonly used. I would also like to track some more information using campaign/source/medium options in GA but I'm having a tough time getting these to show in the reports - the link I'm using is below (utmac switched out for obvious reasons):
https://www.google-analytics.com/__utm.gif?utmdt=ShortUrl+Redirect&utmp=%2f3f20118&utmac=UA-9999999-99&utmcc=__utma%3d.1675621744.1591667140.64981.1591667140.64981.1591667140.64981.1%3b%2b&utm_source=TestSource&utm_medium=TestMedium&utm_campaign=TestCampaign
I see the hit but it shows with a medium of "(none)" and source of "(direct)" when I'm expecting to see "TestSource" / "TestMedium"... Is it that I'm constructing the URL wrong or a miss in GA setup?
I've also tried putting the utm_source/campaign/medium as part of the utmp address as query string values but no luck: https://www.google-analytics.com/__utm.gif?utmdt=ShortUrl+Redirect&utmr=0&utmp=/3f20118?utm_source=TestSource&utm_medium=TestMedium&utm_campaign=TestName&utmac=UA-9999999-99&utmcc=__utma%3d.29260146.1591743271.10202.1591743271.10202.1591743271.10202.1%3b%2b
You have to add utm parameters to the querystring of website URL.
I am building an AMP website, and I use google analytics for tracking. However I found the utm_campaign, utm_source and utm_medium properties are not working when I migrate my site to AMP, it was working when I was using analytics.js. I tried to add ?utm_source=some_value&utm_campaign=some_value&utm_medium=some_value at the end of url, it doesn't work. I tried to add these values through extraUrlParams in the amp-analytics configuration like this: "extraUrlParams": {"utm_source": "test", "utm_campaign": "test", "utm_medium": "test"}, it doesn't work as well.
After some further digging, this problem solved. Here is how to solve the issue.
When a request comes in with ?utm_campaign=some_value&utm_medium=some_value&utm_source=some_value, it probably not the actual link amp-analytics send to GA. Actually it is sending the page_location in the amp-analytics configuration.
So if your configuration is like this: {"vars": {"gtag_id":"UA-XXXX-0", "config": {"UA-XXXX-0": {"page_title":"some_value","page_location":"$urlWithParams"}}}}, e.g. current page location is https://example.com/ , then the page_location should be like https://example.com/?utm_campaign=some_value&utm_source=some_value&utm_medium=some_value , then it will capture the UTM values. To achieve this, you can either get the current window location or url params using AMP url variables.
When I send a one-off document to RightSignature via their API, I'm specifying a callback location in the XML document as specified in RightSignature's schema definition. I then get a signer-link value back from their API for the document. I display the HTML response from the signer-link URL in an iFrame on our website. When our user signs the document in this iFrame, which is rendering the responses from their website, I want their website to post to our callback location.
Can I do this with the RightSignature API and does it make sense?
So far, I'm only getting content in the iFrame that indicates that the signing was successful. The callback location does not seem to be getting called.
I got it solved just now. Basically, i was doing two things wrong first you have to go in RightSignature Account and set it there the CallBack url
Account > Settings > Advanced Settings
But the thing which RS is unable to mention to us that this url can not be of localhost, but it should be of https i mean like Live URL of your site like
https://stagingmysite.azurewebsites.net/User/CallBackFunction
And then in your CallBack just write these two lines and you will receive complete XML which would have the GUID and document status as well.
byte[] data = Request.BinaryRead(Request.TotalBytes);
string callBackXML = System.Text.Encoding.UTF8.GetString(data);
I found the answer with some help from the API team at RightSignature. I was using callback_location but what I really wanted is redirect_location. Their online documentation was difficult to follow and did not clearly point out the difference.
I got this working after a lot of trial and error.
I have the Snowplow event tracker snippet included on my website using Google Tag Manager, and Snowplow events are indeed being sent as GET requests to the endpoint I've configured. Many of the params from the Snowplow tracker protocol are present in the requests. However, I used
window.snowplow('setUserId', 'XXXX');
in the Tag to set the uid param, but it doesn't appear in the request. How can I enable it?
The Snowplow documentation implies this event is included automatically.
Try Modify the name "snowplow_name_here" ,some words not working.
example, if your name , start with "option", don't work.
I want to track clicks with google analytics. Is there any tutorial for this?
I use the following jQuery code to add event tracking, assuming, that all external links begin with http://:
$(document).ready(function() {
$("a[#href^='http://']:not(.internal)").addClass("external").bind('click keypress', function(event) {
var code=event.charCode || event.keyCode;
if(!code || (code && code == 13)) {
if(pageTracker){
pageTracker._trackEvent('outgoing', 'click', this.href);
};
};
});
GA doesn't auto-track external links, so you have manually call one of its functions on all your exit links. You can track it as a virtual page view or as a custom variable or event, passing the relevant information you want to track, to the GA functions (like the exit link url).
Depending on how your links are setup, you can easily setup an click event listener to trigger the GA function call. For example, if all of the exit links have a specific css class attribute associated with them then you can hook the click event to that.
If all of your exit links point to your php script and only pass an ID number to it or something (no actual exit url), then you will not be able to pass to GA the exit link url. If you are fine with just passing the ID then you can use that instead of the url and pass as the virtual url or custom variable value "/exit/[id]" or whatever else makes sense to you. And you can also look for the php script's url as a way to hook the click event to all your exit links, if there is no other unique identifier.
If none of this is an option and you have to do it server-side...then you're kind of out of luck on doing it the "easy" way. GA has an API for interacting with it via server-side code but it's only 1-way. You can use it to get information out of GA but you can't use it to put information into it.
However, what you CAN do is...when a request to GA is made, take a look at that request in Firebug > NET tab or in Charles Proxy or some other request sniffer program, or take a look at the GA's url in its noscript tag. The way it works is a request is made to the GA server and variables and values are appended to the url as a query string.
So what you can do is build a url like that and use cURL to make a request to the GA server...but here's the tricky part: you have to fool GA into thinking the request was made from a browser, not your server. So you need to make sure you send header information with the cURL request to make it look like a browser made the request. Ideally you will want to use whatever header information was sent to your server from the client so that GA can record the hit as if it were the user, so that reports can populate accordingly.
You could send the requests to your server, and your server could send the user a 301 redirect.
Your could then do server-side google analytics, by sending requests to http://www.google-analytics.com/utm.gif to google, like this project does: http://code.google.com/p/php-ga/
You can use this jQuery library to help with sending click events to GA:
https://github.com/spilliton/track_that