-
Notifications
You must be signed in to change notification settings - Fork 133
Description
About the behavior that amp_device_id is not set when deviceIdFromUrlParam is true
I'm using amplitude-js 7.1.1.
I'd like to get some feedback on whether this behavior is a bug or not(or is there an another solution I want to do)
As we are trying to connect anonymous users by device ID only on the two sites, I set the deviceIdFromUrlParam to true and send the amp_device_id to a specific hostname as shown below. But initially, amp_device_is is not set, then the device_id becomes null.
I understood "deviceIdFromUrlParam is true" to mean that I must first set amp_device_is to the URL, is that correct?
var sendDeviceIdHosts = ['www.example.com'];
var apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var userId = null;
var options = {deviceIdFromUrlParam: true, includeUtm: true};
var callBack = function(instance){
var deviceId = instance.options.deviceId;
console.log('deviceId is ' + deviceId);
var links = document.getElementsByTagName('a');
links.forEach(function(link) {
for(var i=0; i<sendDeviceIdHosts.length; i++){
if ( link.hostname === sendDeviceIdHosts[i] ) {
link.search += link.search.length > 0 ? '&':'' + 'amp_device_id=' + deviceId;
break;
}
}
});
If the amp_device_id is not set, I think a better solution is to create a base64Id.
For example, if 'this._getDeviceIdFromUrlParam(this._getUrlParams())' returns null, you can use base64Id instead.
Amplitude-JavaScript/src/amplitude-client.js
Line 286 in bec6e50
return this._getDeviceIdFromUrlParam(this._getUrlParams()); |
If you need to create a new pull request, please let us know.