Hi Amplitude,
We want to cross domain tracking for our landing site and product site. We found guide for cross domain tracking for JS https://developers.amplitude.com/docs/advanced-settings, but cant find the guide for typescript. How should I configure for cross domain tracking with typescript SDK then?
Thanks in advance.
Hi shirleyfang,
Cross domain tracking should be handled relatively the same as the legacy JS SDK with slightly different syntax, but you can find our documentation on this in our new developer docs which I'll include a snippet of here: https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#cross-domain-tracking
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.orgUsers 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.
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:
www.example.com
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.
deviceId
getDeviceId()
www.example.com?deviceId=device_id_from_site_1
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.
init
init('API_KEY', null, { deviceId: 'custom-device-id' })
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!
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.
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.
amplitudeGTM.getDeviceId()
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._iq["instance-name"].getDeviceId() to access the device id. Thanks for all the help!
amplitudeGTM._iq["instance-name"].getDeviceId()
Good to hear. The details for different situation has been explained in the readme file.
To summary
Also, we are working on improving our GTM doc, we will also include the cross-domain section there and improve this script.
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...
I am running into a loop when attempting to import data from BigQuery. At origin, my data is already in milliseconds since epoch. If I query: event_time as time, I get the error: 1.'time' column should be a TIMESTAMP_NTZ column (Snowflake) or a TIMESTAMP column (BigQuery). example for the type of 'time' column is…
How do I transfer data from one amplitude account to another? It seems all the community chats about this have completely broken links. Easy to export, no way to import, very frustrating. :(
When using @amplitude/plugin-web-vitals-browser with Create React App v4 (react-scripts@4.0.3), the build fails with: ./node_modules/@amplitude/plugin-web-vitals-browser/node_modules/web-vitals/dist/web-vitals.js<br /><br />SyntaxError:…
Hello, I'm using SpringBoot and Kotlin to integrate with the Amplitude Export API. The official Amplitude documentation (https://amplitude.com/docs/apis/analytics/export) states that "data is available to export at a minimum within 2 hours of when the servers received it." However, there's no clear information about the…
Hello, Is there a way to make a query like: “Give me all the users that have the user property X equal to 10”, by using just any of the APIs, without making a cohort first through the Amplitude’s UI? Thank you!