I'm trying to use Google Analytics 4 to track payment errors with Stripe.
I'm using Drupal 8; here is the relevant JS:
// Helper to handle the Stripe responses with errors.
var stripeErrorHandler = function (result) {
if (result.error) {
// Inform the user if there was an error.
// Display the message error in the payment form.
Drupal.commerceStripe.displayError(result.error.message);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('event', 'exception', {
'description': result.error.message,
'fatal': false
});
// Allow the customer to re-submit the form.
$form.find(':input.button--primary').prop('disabled', false);
}
The gtag() function is taken from the Google developer documentation for pushing exceptions in GA4.
I turned on debug mode in Analytics, went to the checkout page, and input an invalid expiration date.
In the Chrome dev console, I can see that the exception is logged:
Processing GTAG command: ["event", "exception", {description: "Your card has expired.", fatal: false}]
However, the exception does not actually get logged in Analytics. What more do I need to do to get the exception logged?
Related
The bounty expires in 2 days. Answers to this question are eligible for a +100 reputation bounty.
thumbtackthief wants to draw more attention to this question.
I'm trying to get a count of the number of people currently viewing my site. With Google Analytics about to switch over to GA4 from UA, I figure it's best to use GA4 but the documentation--especially for the API--is pretty weak. I believe I need to query the Realtime API but I'm having trouble putting together the request to do it. Right now I'm stuck on the authorization step, but I'm not really sure any of it makes sense in the first place. I've created a service account in Google Analytics.
Here's what I have at the moment, cobbled together from a variety of sources, currently giving me a 401 error:
<div id="active-users"></div>
<script src="https://apis.google.com/js/client.js"></script>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="{SERVICE_CLIENT_ID}.apps.googleusercontent.com">
<script>
// Load the Google Analytics API client library
gapi.load('client', function () {
gapi.client.init({
client_id: '{SERVICE_CLIENT_ID}',
apiKey: '{API_KEY}'
}).then(function () {
gapi.client.request({
path: '/v1/data/realtime:get',
params: {
ids: 'GA4:{PROPERTY_ID}',
metrics: 'rt:activeUsers'
}
}).then(function (response) {
var activeUsers = response.result.totalsForAllResults['rt:activeUsers'];
document.getElementById('active-users').innerHTML = 'Active users: ' + activeUsers;
});
});
});
</script>
EDIT:
I am trying to follow this documentation, which seems relevant, but I can't find any information on how to translate this to the Client Library
I have a node application. Here I'm trying to fetch the referral flow from google analytics using Google API. I have mentioned the dimensions, metrics and other required parameters. Here is my code snippet,
// imported googleapis npm module
import google from "googleapis";
const analytics = google.analytics("v3");
// This is my payload to get the required analytics data
const analyticsData = {
auth: oauth2Creds,
accountId: "accountID",
webPropertyId: "webPropertyID",
profileId: "profileID",
ids: "ga:id",
"start-date": "90daysAgo",
"end-date": "today",
metrics: "ga:pageValue,ga:pageviews,ga:entranceRate,ga:exitRate",
dimensions: "ga:fullReferrer",
"start-index": "1"
};
// Function to get analytical data using the above payload
analytics.data.ga.get(analyticsData, (err, result) => {
// I will get the results here
console.log(result);
});
Here it returns only the data related to the entrance. But I need to get the flow for each referral visits. For ex, if a user enters into the home page from google and moves to page2, page3 and exits the website, then I need to track this flow. How can this be done using google analytics API?
I might not be answering your question directly but I think the following documentation might assist you.
https://developers.google.com/analytics/devguides/reporting/mcf/v3/
I want to be able to resend an email verification link to users of my Meteor application in case they accidentally delete their email verification email.
I have a link with the id "resentEmailVerificationLink"
I have the following code in my client for when the link is click (alerts are just there to show myself how far the function gets before an error):
Template.dashboard.events({
'click #resentEmailVerificationLink' : function(event) {
event.preventDefault();
var id = Meteor.userId();
alert('clicked: ' + id);
Accounts.sendVerificationEmail(id);
alert('Verification Email resent');
return false; // Stops page from reloading
}
)};
I know the sendVerificationEmail is a server function but I have no idea how to call this function in the server upon clicking the verify email link (I'm a bit of a Meteor newbie).
Any idea of how to accomplish this, because currently it doesn't work with the following error: Uncaught TypeError: Accounts.sendVerificationEmail is not a function
Note: Meteor.Accounts.sendVerificationEmail(id); doesn't work either (it does however produce a different error.
You can try with server side method just create one pass the attrs and call http://docs.meteor.com/#/full/accounts_sendverificationemail on the server. More about meteor methods: http://docs.meteor.com/#/full/meteor_methods
In my Meteor.js application, I'm using the accounts-google package in order to be connected with a google account. I have two questions about it.
First, is there a simple way to filter the account used? I would like that the users can connect only with google accounts belonging to my company. Our google account mails end with #mycompany.com. So it would be a simple mail filtering.
I already done that with some post log in hooks but I was wondering if there was a simpler way for doing it.
My second question is how to force the opening of the google account choser. For now, if I try to connect with a wrong google account, and if I only added this account (like in gmail, drive, etc), the google choser doesn't pop and automatically connect with this wrong account. So, in this case, the user is totally blocked (my application disconnect him if he tries to log in with a wrong account but the google account module doesn't propose him to connect with another account).
Thank you for your help.
In order to restrict signup/login to your domain, simply do on the server:
var checkEmailAgainstAllowed = function(email) {
var allowedDomains = ['mycompanydomain.com'];
var allowedEmails = ['otheruser#fromotherdomain.com','anotheruser#fromanotherdomain.com'];
var domain = email.replace(/.*#/,'').toLowerCase();
email = email.toLowerCase();
return _.contains(allowedEmails, email) || _.contains(allowedDomains, domain);
};
Accounts.config({
restrictCreationByEmailDomain: function(email) {
if (!email) {
throw new Meteor.Error(403,'This email address is not allowed');
}
if (!checkEmailAgainstAllowed(email)) {
throw new Meteor.Error(403,'This email domain is not allowed');
}
return true;
}
});
And to login, you'll need on the client:
Meteor.loginWithGoogle({
forceApprovalPrompt: true, //this is what you want, to rerequest approval each time that prompts the google login prompt
loginStyle : "redirect", //or not, depending on your need
requestPermissions : ['profile', 'email'],
requestOfflineToken: true
}, function (err) {
if (err)
// set a session variable to display later if there is a login error
Session.set('loginError', 'reason: ' + err.reason + ' message: ' + err.message || 'Unknown error');
});
Side note:
Alternatively, you can set up your routes so that every time a new route is called, you login, and every time a route is destroyed or on windows's unload, you call logout. This causes login/logout roundtrip everytime the route changes, but you'll make sure that the new user always has a fresh session
Edit:
When you log out of your meteor app, you don't log out of google. That's how oauth works. So, basically, if you want a meteor log out to also log the user out of their google account, so that the next time they come back, they need to provide credentials again, you should do:
Meteor.logout(function(e) {
if (e) {
console.log("Could not log the user out")
} else {
window.location.replace('https://accounts.google.com/Logout');
}
});
This uses the callback of Meteor.logout() so that when the logout is successfull, the user is redirected to google's central account logout url where the user is also logged out of all google services.
I'm trying to get have users be able to post to their Facebook walls on my external site.
I've encountered a problem in Safari. If the user isn't logged in, i.e. they have not gone through the flow that calls FB.login(), I get the following JS error when calling FB.ui():
TypeError: 'undefined' is not an object (evaluating 'b.fbCallID=a.id')
However, if they are logged in, the dialog appears just fine.
FB.ui() is called in a callback function -- I'm retrieving a unique url from my server, and then calling FB.ui(). If I call FB.ui() directly, it works fine, but not when it's asynchronous.
Here's the code:
retrieveUrl(param1, param2, function(result) {
FB.ui({ method: 'feed',
description: 'My Description',
display: 'dialog',
link: result.uniqueUrl,
picture: 'http://foo.com/bar.jpg'
}, function(response) {
if (response && response.post_id) {
//Posted message
} else {
//Not posted message
}
});
});
This works in other browsers, regardless of logged in state or not.
FB.login or FB.ui methods must be called on a user initiated action (click) in Safari for new window/popup/iframe to be rendered by FB.UIServer.
If you try calling these methods on a network callback event it will be blocked and the exception you described will occur:
TypeError: 'undefined' is not an object (evaluating 'b.fbCallID=a.id')
Can you retrieve the unique URL before the user interacts with the page and then present the feed dialog when they click on a button?