You can track anonymous behavior across two different domains. Amplitude identifies anonymous users by their device IDs which must be passed between the domains. For example:
Site 1: www.example.com
Site 2: www.example.org
Users who start on Site 1 and then navigate to Site 2 must have the device ID generated from Site 1 passed as a parameter to Site 2. Site 2 then needs to initialize the SDK with the device ID. The SDK can parse the URL parameter automatically if deviceId is in the URL query parameters.
From Site 1, grab the device ID from getDeviceId().
Pass the device ID to Site 2 via a URL parameter when the user navigates. (for example: www.example.com?deviceId=device_id_from_site_1)
Initialize the Amplitude SDK on Site 2 with init('API_KEY', null).
If the deviceId isn't provided with the init like init('API_KEY', null, { deviceId: 'custom-device-id' }), then it automatically fallbacks to use URL parameter.
Hope this helps!
For instructions like “grab the ID with getDeviceId()” is that possible to do with Google Tag Manager? Trying to understand how we would do this in our setup more specifically, which is mostly GTM with some app SDK. Or is it an event we would set up in Amplitude? We’re mid-implementation but want to understand this better.
Thank you
@mkoiva Hi! Thanks for writing in and apologies for the delay. I’ve shared your question over to our support team who can help get this sorted and also other implementation questions you might have.
Following
Thanks @shirleyfang, when you say “passed as a parameter” and “Pass the device ID to Site 2 via a URL parameter “ where specifically is that referring to or how would we accomplish that? We’re using the GTM SDK and trying to understand how this would be accomplished. Thanks
@Esther Trapadoux I am having the same issue as @mkoiva and am frantically looking for a solution. Is this achievable though GTM or a combination of react/js and GTM? Thanks!
@mkoiva Hi! Thanks for writing in and apologies for the delay. I’ve shared your question over to our support team who can help get this sorted and also other implementation questions you might have.
@Linus Lennstrand talk to your Amplitude representative or contact. We worked with ours and they gave us a cross domain work around. They are working on making it live in the GTM template but it is not live there yet.
@Linus Lennstrand talk to your Amplitude representative or contact. We worked with ours and they gave us a cross domain work around. They are working on making it live in the GTM template but it is not live there yet.
Thanks a lot! Can you share some details of that solution while I wait for their reply?
Hi @Linus Lennstrand
This is the cross-domain workaround. https://github.com/amplitude/GTM-cross-domain-script. This script will append deviceId into the URL during redirect. If the other domain has amplitude installed, the SDK will auto-capture the deviceId from the URL and set that deviceId for you.
Thanks.
Hi @Linus Lennstrand
This is the cross-domain workaround. https://github.com/amplitude/GTM-cross-domain-script. This script will append deviceId into the URL during redirect. If the other domain has amplitude installed, the SDK will auto-capture the deviceId from the URL and set that deviceId for you.
Thanks.
Thanks a lot @Alyssa Yu! I’ll try this out right now.
@Alyssa Yu I have tried this now and unfortunately it’s still not working. The script is running, but it eventually times out. I have attached the console log messages and from what I can see amplitudeGTM.getDeviceId() returns undefined.
I realised I missed changing to the custom instance name. After doing that, I can access the amplitude instance through the console, however the script is still not working.
Ok, problem solved! The issue was that we are running a non-standard Amplitude instance name, so had to change the code to use amplitudeGTM._iqq"instance-name"].getDeviceId() to access the device id. Thanks for all the help!
Good to hear. The details for different situation has been explained in the readme file.
To summary
if you are using default instance, you can access the deviceId by amplitudeGTM.getDeviceId()
if you are using customized deviceId, you need to access the deviceId by amplitudeGTM._iqM"instance-name"].getDeviceId() .
Also, we are working on improving our GTM doc, we will also include the cross-domain section there and improve this script.
Thanks.
Thanks @Alyssa Yu! And yes, I did realise from the readme file how to get access to the customised instance. And that worked really well in code! However, the script did not work when I ran it through GTM, it kept timing out just like before I modified the code. So we eventually stopped trying to fix the script in GTM and just put the deviceId on the querystring “manually” instead...
If you don't have an Amplitude account, you can create an Amplitude Starter account for free and enjoy direct access to the Community via SSO. Create an Amplitude account. You can also create a Guest account below!
If you're a current customer, select the domain you use to sign in with Amplitude.
If you don't have an Amplitude account, you can create an Amplitude Starter account for free and enjoy direct access to the Community via SSO. Create an Amplitude account. Want to sign up as a guest? Create a Community account.
If you're a current customer, select the domain you use to sign in with Amplitude.