What is the best-supported approach for tracking logged-in Usernames/Ids in App Insights telemetry?
A User with Username "JonTester1" said some Pages he visited 4 hours ago were really slow. How can I see everything JonTester1 did in App Insights to trouble shoot/know which pages he's referring to?
Seems like User Id in App Insights is some Azure-generated anonymized thing like u7gbh that Azure ties to its own idea of the same user (thru cookie?). It doesn't know about our app's usernames at all.
I've also seen a separate field in App Insights called Auth Id (or user_AuthenticatedId in some spots), which looks to sometimes have the actual username e.g. "JonTester1" filled in - but not always... And while I don't see any mention of this field in the docs, it seems promising. How is our app's code/config supposed to be setting that Auth Id to make sure every App Insights log/telemetry has it set?
Relevant MS docs:
https://learn.microsoft.com/en-us/azure/azure-monitor/app/usage-send-user-context
This looks to just copy one library Telemetry object's User Id into another... no mention of our custom, helpful Username/Id anyway... and most in-the-wild examples I see don't actually look like this, including MS docs own examples in the 3rd link below; they instead hardcode get a new TelemetryClient()
https://learn.microsoft.com/en-us/azure/azure-monitor/app/website-monitoring No mention of consistently tracking a custom Username/Id
https://learn.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics#authenticated-users Shows some different helpful pieces, but still no full example. E.g. it says with only the setAuth... JS function call (still no full example of working client-side JS that tracks User) on the page, you don't need any server-side code for it to track custom User Id across both client-side and server-side telemetry sent to Azure... yet then it also shows explicit code to new up a TelemetryClient() server-side to track User Id (in the Global.asax.cs or where?)... so you do need both?
Similar SO questions, but don't connect the dots/show a full solution:
Azure Insights telemetry not showing Auth ID on all transactions
Application Insights - Tracking user and session across schemas
How is Application insight tracking the User_Id?
Display user ID in the metrics of application Insight
I'm hoping this question and answers can get this more ironed out; hopefully do a better job of documentation than the relevant MS docs...
The first link in your question lists the answer. What it does show you is how to write a custom telemetry initializer. Such an initializer lets you add or overwrite properties that will be send along any telemetry that is being send to App Insights.
Once you add it to the configuration, either in code or the config file (see the docs mentioned earlier in the answer) it will do its work without you needing to create special instances of TelemetryClient. That is why this text of you does not make sense to me:
[…] and most in-the-wild examples I see don't actually look like this, including MS docs own examples in the 3rd link below; they instead hardcode get a new TelemetryClient()
You can either overwrite the value of UserId or overwrite AuthenticatedUserId in your initializer. You can modify the code given in the docs like this:
if (requestTelemetry != null && !string.IsNullOrEmpty(requestTelemetry.Context.User.Id) &&
(string.IsNullOrEmpty(telemetry.Context.User.Id) || string.IsNullOrEmpty(telemetry.Context.Session.Id)))
{
// Set the user id on the Application Insights telemetry item.
telemetry.Context.User.AuthenticatedUserId = HttpContext.Current.User.Identity.Name;
}
You can then see the Auth Id and User Id by going to your AI resource -> Search and click an item. Make sure to press "Show All" first, otherwise the field is not displayed.
Auth Id in the screenshot below is set to the user id from the database in our example:
We access the server from azure functions as well so we set the user id server side as well since there is no client involved in such scenarios.
There is no harm in settting it in both places, javascript and server side via an initializer. That way you cover all scenario's.
You can also manually add user id to app insights by
appInsights.setAuthenticatedUserContext(userId);
See App Insights Authenticated users
I'm building a Python Flask web application that performs an analysis based on the inputs a user enters. I want to allow the user to send this analysis to their Facebook friends as a link; therefore, I need the analysis page to have a unique URL for every instance.
My approach up to this point has been to build the analysis page URL like so:
website.com/results/<Facebook ID>/<time in seconds since the epoch>
I'm using time.time() for the last parameter and the analysis data (paired with the FB ID and time) is stored in a database. An example URL might look something like this:
website.com/results/1619598720181063/1508036889
Does this approach seem feasible, are there best practices for generating a persistent unique URL, or is there a much better approach I'm overlooking?
Note I'm using Facebook's Send Dialog to share the link.
You might consider letting the database handle it for you by using an auto-generated unique key for the data. Key are guaranteed unique and your URI could be even simpler: results/123
I am working on an MVC application that is currently sending an email to JIRA and it is creating an issue. I am currently configuring all of the required fields and currently the issue being created has the issue Type set to bug as a default and also I think the priority set to minor.
I need to be able to change these two fields from the default as this application is used for clients that need to choose the correct issue and priority.
Currently I am using the TO, FROM, CC as the assignees, client and reporter. The summary and description are used by the subject and body respectively. This is why I don't know if it is actually possible to change these.
Can this actually be done, for example in the body "issueType" = "BUG", or "issueType":"Task"?
The application has the IssueType and Priority as dropdown list so could I append this to the body or maybe the subject of the email and send it. All code is working just need to know how/if I can set these two properties.
Update
I saw an example of this being used but I am unsure of how to implement this into an email form or if this can be done. And I am also using smtp gmail to send the information in my MVC application.
handler.params: project=XXOODD, issuetype=2
https://answers.atlassian.com/questions/39041/jira-creating-issues-and-comments-from-email
By default this cannot be done, but by using a couple of add-ons you can successfully get it to work:
https://marketplace.atlassian.com/plugins/com.metainf.jira.plugin.emailissue
https://marketplace.atlassian.com/plugins/com.javahollic.jira.jemh-ui
I've been searching for a solution to this, which I thought would be trivial, and seems pretty much impossible.
Here's the situation: I set up an AdWords campaign, ad groups and ads. I point them to www.mysite.com
Once visitors arrive to my site through one of my ads, I want to know which exact ad they clicked on (and campaign, as apparently the ad id isn't globally unqiue). Is this possible?
I first tried by enabling Destination URL auto-tagging, but seems like the gclid parameter is pretty much useless.
Then I looked at the UTMZ cookie, but it seems like at most (correct me if this isn't the case), you get the campaign number (is this even the ID in AdWords?) and the keywords searched or the ad's keywords, one of those. Not anything I can uniquely identify the ad by, right?
Finally, I looked at ValueTrack, although again correct me if I'm wrong, but this would mean manually changing the destination URL of each of my ads in AdWords, right? Even doing this, I'm not sure I can get something that lets me uniquely identify the clicked ad. Is {creative} what I want? It's described in the docs as the "unique ID of the creative", does that mean this includes the Campaign.Id and the AdGroupAd.Id?
Thanks!
There is a way to do what you want using tracking templates.
Navigating to auto-tracking and tracking template settings:
Log in to Adwords, and click "Campaigns".
Click "Shared Library" in the bottom left corner.
Under "Shared Library", click "URL options".
You'll now get these options:
These options are set for the entire account. I think it is possible to override the tracking template for individual campaigns, ad groups and ads. Here is what they mean:
Auto-tagging
Auto-tagging means that when a user clicks on an ad, they will go a URL with the gclid parameter appended, for example http://yourwebsite.com/?gclid=example. This value is useful for some things, such as for offline conversions, so your website should save it.
Tracking template
Tracking template means that when a user clicks on an ad, they will be directed to this URL. Interestingly, it does not have to be your website, as long as the URL redirects to your website. For instance, you could set it up to look like this:
http://trackingcompany.com/?url={lpurl}&campaignid={campaignid}
{lpurl} and {campaignid} are placeholders which AdWords recognises and knows how to handle. So, for example, if a user clicks on an ad, they could go to:
http://trackingcompany.com/?url=http%3A%2F%2Fyourwebsite.com&campaignid=543987
trackingcompany.com must redirect the user now to http://yourwebsite.com, otherwise, it is in violation of AdWords policy and your ads could be rejected.
Now, here's the clever bit that I didn't realise because all of this is badly documented: you don't have to use a third-party tracking company to get access to things like campaign id. You can just reuse your own website! Just set your tracking URL to something like this:
{lpurl}?campaignid={campaignid}
You see that? {lpurl} will get replaced with the landing page, which is your website! So the user in our example would go to this URL upon clicking an ad:
http://yourwebsite.com?campaignid=543987
It's not clear to me whether example.com must now redirect to the landing page URL without those parameters, or not.
I can't find documentation on these placeholders anywhere, but these are the ones that I've found work:
{lpurl} landing page URL
{campaignid} campaign ID
{adgroupid} ad group ID
{creative} creative or ad ID
{keyword} keyword
Auto-tagging and tracking template together
If you enable both auto-tagging and a tracking template, then AdWords would behave as it normally does with a tracking template, appending a gclid query parameter.
Addendum: ignoring these new query parameters in Google Analytics:
If you use Google Analytics, you probably want to ignore these query parameters, merging hits with these parameters with hits that don't have them. You can do that by setting the "Exclude URL Query Parameters" option to aw_campaignid,aw_adgroupid,aw_creative,aw_keyword. You can't apply this retroactively, so do this before making any AdWords changes.
As far as I know there is no value track for campaign or ad group ID. You could just append something to the end of each ad's destination URL based on the campaign & ad group, but that is a bit of a chore.
If you link your Google Analytics & AdWords accounts and use auto-tagging in AdWords you can get the information you want in GA through the AdWords report (shows campaign, ad group, keyword etc). GA is able to use the gclid to retrieve data from AdWords, and I think you can then use the GA API to get the campaign data back out if you want it.
You could:
turn off auto-tagging
pull the entire account into an excel file
insert a new column for each desired output variable (Campaign, ad id [like Headline?])
trim, lower, and find/remove spaces from the target columns (so something like: campaignname, compressedheadline)
then concatenate that column with your destination URLs and a UTM string like this:
?utm_source=google&utm_medium=ppc&utm_content=compressedheadline&utm_campaign=campaignname
use this function and replace with the appropriate columns
=concatenate([dest url column],"?utm_source=google&utm_medium=ppc&utm_content=",[compressedheadline column],"&utm_campaign=",[campaignname column])
if the functions for the parts between the quotes break the formula, paste them into their own cells and then reference the cells in the concatenate function.
Drag this formula down the entire account,
Copy / Paste Special / Paste Values of the new Destination URLs over the old Destination URLs.
Remove unnecessary columns that have been created between Campaign, Ad Group, Headline, Description Line 1, Description Line 2, Display URL and your new Destination URL.
Then highlight just the Campaign, Ad Group, Headline, Description Line 1, Description Line 2, Display URL and your new Destination URL and you can paste this into the AdWords Editor under "add/update multiple ads.
You can get this data from the CLICK_PERFORMANCE_REPORT - The only downside to this, is that this report can only be run for 1 day. so if you needed a month worth of data - you would have to run about 30 reports -
The ad Id is the "CreativeId" - you can get the campaignId and Adgroup ID as well from this report - there is 1 row for each click - (GCLID) these are unique.
see this link for more info on what fields are available
https://developers.google.com/adwords/api/docs/appendix/reports#click
What would be the best way to go about giving users the ability to share a private link that enables anyone who clicks it to view a certain page/document/item that have privacy restrictions in place?
In my case:
A User creates events which are limited to certain groups of relationships in the database (namely: friends, friends of friends, etc.) I have a :before_filter in the event controller that checks the eligibility of the current logged in user to make sure that that user has permission to see the event. If they don't they get booted to the root page with an error message.
However, I want a special scenario to exist where a user can create an event with those same privacy settings and IN ADDITION, be able to share a special link with his or her friends via e-mail, facebook, etc. Those users do NOT need an account (but will need to make one in order to sign up for the event). This is important because there is also a :before_filter in the application_controller which makes sure a user is logged in.
I'm thinking there is something I could do with routing here... Right now I just have the simple /events/72 setup. Should each event have two different links: a normal one, and a "special code" version which enables them to bypass those two :before_filter?
What are people's thoughts?
I agree with David Lyod's answer (separating this concern in a different controller).
But for creating the hash I strongly recommend you salting the hash with some secret phrase.
require "digest"
Digest::SHA512.hexdigest("#{created_at}#{user_id}.mysupersonicsecretSALT")
Doing this it is not possible, without the knowlegde of the secret phrase, to calculate the hashes and test them against your system until it hits an existing one.
If you're handling sensitive data you should not be lazy.
Cheers,
Lukas
I would have a separate controller that uses a hash value to reference the event.
Something simple like the created_at + user_id hashed to create a unique reference.
You could also simply skip the check on a certain action but I would much prefer the first solution .