Skip to content

About the behavior that amp_device_id is not set when deviceIdFromUrlParam is true #302

@aoshika-lv

Description

@aoshika-lv

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.

return this._getDeviceIdFromUrlParam(this._getUrlParams());

If you need to create a new pull request, please let us know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions