Google Tag Manager allows you to add a User ID… Is there a way to insert the Member ID for this for Ghost Members?
gtag(‘set’, {‘user_id’: ‘USER_ID’}); // Set the user ID using signed-in user_id.
Google Tag Manager allows you to add a User ID… Is there a way to insert the Member ID for this for Ghost Members?
gtag(‘set’, {‘user_id’: ‘USER_ID’}); // Set the user ID using signed-in user_id.
Hey @nearkingdom,
At the moment there isn’t an ideal piece of data attached to the member that you could use in this scenario. I would’ve suggested using the the members email, but that would be identifiable information on them. We’re considering exposing a member ID
, do you think that would be of use to you?
This was released in 3.9.0 :)
Nice spot @vikaspotluri123, we exposed it for this sort of use case. Hopefully you find it useful with gtag
@nearkingdom
Hi. Which code i need to add at GTM script to set up tracking members User-ID?
This is exactly the type of thing I am looking for. I am hoping to pass member info to Drift so I can offer live chat to just the paid members. Any tips on how to start implementing the code,
The uuid
should be the right thing to use, check out the members docs here:
I think you’d need to add some code to your theme’s default.hbs
template, similar to how the Amplitude integration works.
For example, you’d add this just before the closing </head>
tag in your default.hbs
for Gtag:
{{#if @member}}
gtag('config', 'GA_MEASUREMENT_ID', {
'user_id': '{{@member.uuid}}'
});
{{/if}}
(Google’s docs reference here)
Full disclosure, haven’t tested this myself yet. But hopefully this will help!
Edit: Forgot the brackets for {{@member.uuid}}
Kym, thank you so much!
Curious, why isn’t member ID exposed using @member.id
?
Developing an integration and need to read user using @tryghost/admin-api
, but looks like uuid
isn’t an attribute one can use to target user.
@sunknudsen API docs for members are still in the works at the moment.
Our Zapier integration is open source though, so you could use that as a reference point: GitHub - TryGhost/Zapier: Ghost <-> Zapier Integration.
This link looks outdated based on the card. I found this page helpful.
Is there any way to do this with a default theme? Code injections settings seem to not recognise any handlebars tags.
Right, handlebars happens on the server, and code injection javascript happens in the client.
HOWEVER, I think there is a workaround that’ll work in code injection. Write some javascript that makes a GET request to your site’s /members/api/member/
endpoint. That returns a JSON object that includes the uuid (or null, if the user is not logged in), that could then be used to call gtag.
Will it work? Not sure. But it’s probably worth a shot, if you need it and can’t just add Kym’s small snippet of code to your theme.
Thank you for the suggestion @Cathy_Sarisky, I have not tried it but it think it could work. I decided to modify the theme instead, by editing the default.hbs. My the question was based on a wrong assumption that it is impossible to edit the default theme , but later I found the download theme button and just updated it.