Integrating Google Analytics with embed script Answered
Hello everyone,
I am trying to put the embed script in a Webflow Project to integrate Google Analytics.
<script> window.onload = function () { MemberStack.onReady.then(async function(member) { console.log('memberstack is ready, memeber = ', member) var metadata = await member.getMetaData(); if (metadata.signupAt == null) { console.log('memberstack detected new signup') member.updateMetaData({ signupAt: Date.now() }); window.dataLayer = window.dataLayer || []; window.dataLayer.push({'event': 'new_signup', member_id: member.id, email:email }); } }) } </script>
but on console it says "MemberStack" is not defined.
should I define MemberStack as window.$memberstackDom or is it something different?
Comments
7 comments
for the cases, assuming youre using 2.0, I believe it should be await.memberstack instead of MemberStack.onReady
Also, you need to first make sure the dom package is inisialized with const memberstack = window.$memberstackDom
https://developers.memberstack.com/docs/dom-front-end-package
Julian Galluzzo I have used await.memberstack instead of MemberStack.onReady and still have the same issue. it says not defined.
error: Uncaught ReferenceError: await is not defined
Here’s a simplified version of the code I use to wait for $memberstackDom to become available:
Marc Hudson Thanks so much
You probably want to add another Helper function to check whether the member object is empty (logged-out user), otherwise your JS will error when looking to work with the metadata.
Helper to check a key exists in a JS Object.
Which you can use in the original code:
And within the getCurrentMember() callback:
Hope that works. Not easy coding in Slack’s dark-mode 🙂
Needed some input.
I am trying to set-up a reporting (on GA4 or google sheets) which allows us to provide data every time a user logs in. Can anybody guide me how can I set this up?
I don't I can extract the event "Member-login" from memberstack - is there any other way??
Memberstack doesn't have a native integration with Google Analytics.
You would have to create the event in the frontend (Maybe with the help of GTM to be easier) to be able to see it in your reports. You can create a click event or a pageview event if you want to track custom events https://www.analyticsmania.com/post/how-to-track-custom-events-with-google-analytics-4/
However, for member specific events I recommend using the user id property in Analytics, that way you can filter your reports to login users only. https://www.analyticsmania.com/post/google-analytics-4-user-id/
Please sign in to leave a comment.