Trigger an event in GTM if the user is logged in? - google-analytics

I’m trying to trigger a tag (a button click) only when a user is logged in. So, if the user clicks the “write a review” button the event will trigger if the user is logged in, otherwise it won’t trigger.
In the source code log in data is indicated by this string:
<input type="hidden" id="isLoged" name="isLoged" value=“true”>
If the user is logged in the value return “true”, if not it returns “false”.
I’ve searched the web, tried many things but couldn’t find a way to do it.
Thanks in advance any help.

You can do it with a Custom JS variable:
function () {
return document.getElementById("isLoged").value;
}

Related

user input link will go back to login once the user logged in it will go to the link earlier input instead of dashboard

Sorry to ask but I don't what is the exact call on this.
I have a scenario for example I paste this link localhost/Dashboard/Treatment the user will go back to the login page once the user logged it will go to this localhost/Dashboard/Treatment instead of Main Page using asp.net.
I need is only the exactly the call on this process so that I will do the research.
Sorry beginner :)
If you are using login control, you can use DestinationPageUrl property in your code.
If you just use things like text boxes and button controls, then in your Button_Click event, you can just use Response.Redirect("DestinationHere").
If you don't want change anything in your page, you can add return RedirectToAction({actionName}, {controllerName}); in your login method.

asp.net different view for logged user

Let´s say, I have a button in my View. If the page is accesed by logged-in users it should be displayed normally. If it is accesed by non-loged (anonymous) user, I want the button not to be displayed.
The button visibility should not be affected by the user role, just by the fact if someone is logged in.
How can this be achieved ?
I have figured it out. This condition is sufficient for this purpose:
#if (User.Identity.IsAuthenticated)
{
<button>Send</button>
}

Capture cancelling event for Google Sign-in web

I am implementing google Sign in for my web application as describe in https://developers.google.com/identity/sign-in/web/sign-in. Instead of embedded "Google Sign-In button", I made a custom button which trigger a click event to this function "GoogleAuth.signIn()" as stated in Reference. Everything working fine, if user click the button and proceed with the sigin flow. However, the problem was after the button is clicked and the singin window is shown. User now decided to cancel the singin, but no api function call can be use to capture this event and response accordingly to this user action.
https://developers.google.com/identity/sign-in/web/reference#googleauthsignin
You can check whether Promise returned by GoogleAuth.signIn() has been resolved (which means successful sign-in) or rejected (one option is user clicked cancel).
function onFailure(error) {
alert(error);
}
function onSignIn(googleUser) {
alert(googleUser);
}
auth2.signIn().then(onSignIn, onFailure);

How to check for valid user and then continue submitting data

I am using ASP.NET to submit data from a form to a database.
But before submit I want to check if the current user us valid. If not I want to use the login control registration form where an existing user can enter his user id and password then go back to the previous page to submit the form data.
Example:
Assume a page having 3 textboxes and one button. Once the user clicks the button I want to check if the user is already logged in or not. If not I want to open the login page so he can provide his credentials and after that execute the previous page submit function without the user having to click again.
I think you're asking about form validation? The easiest way to do this is with a postback. Put a button on the form, that button will post back the form to itself, and fire the button_Click event. Inside that event you can put some C# code that will validate the user's name and password. Then you can show a label on the form that indicates the credentials are not correct.
Hope that helps!
You can save information about user, using session:
Session["UserLoggedIn"] = true;
When you want to check, if user is logged in, check like this:
if(Session["UserLoggedIn"] != null)
{
// User is logged in
}
else
{
// User is not logged in, so redirect to login page
Response.Redirect("~/login.aspx");
}
if you want to redirect back, after successful log in operation. you can use QueryString. So instead of:
Response.Redirect("~/login.aspx");
redirection will be:
Response.Redirect("~/login.aspx?RedirectUrl=your current form url");
In login page, you can read QueryString:
string redirectUrl = Request.QueryString["RedirectUrl"];
After login operation, use redirectUrl value, to redirect back:
Response.Redirect(redirectUrl);
i hope i have tried to understand you.
firstly, i would like to explain what you want.
You want to check user logged in before submit, and if he is not logged in you want him to redirect to login page after he logs in u want to come back on the same page. and perform your click function.
RetrunUrl
return url in your querystring will help to return to back to your original page. and u can save the details of the previous page in session and once user logs in and redirects back to original back perform your click event there. by validating you session value,
once you are done with your whole process remember to abandon your current session details

Validation using navigation

I have some pages in my website and a left menu control. Control helps to navigate from one page to another.
My query is -> While user try to navigate to another page, I want to impose some validation like in the current page if the form is not saved, user will be asked to save it by using a confirm messagebox and if user presses no button, then user will be allowed to navigate otherwise, system will first save the details and then navigate.
Edit - My page is a content page, I meant, this is using a master page.
Use the following steps
window.onbeforeunload = confirmExit;
and a function that stops/continue the page execution.
function confirmExit() {
var email= document.getElementById("email");
if (email.value != "")
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
The way I would do this is to have an onbeforeunload javascript event fire which gives the user the choice to save the form. I personally would also poll the form saving data back whist they are completing it. I think this is the method SO uses.
There is a pretty decent example over on Code Project that may help http://www.codeproject.com/KB/aspnet/AutoSaveFormData.aspx
EDIT:
If you only want to call the save method you can mark it with the [WebMethod] filter and call it using XmlHttpRequest or jQuery's $.post

Resources