Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aoshika-lv opened this issue Sep 23, 2020 · 3 comments · Fixed by #303
Closed
Labels
question Further information is requested

Comments

@aoshika-lv
Copy link
Contributor

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.

@aoshika-lv aoshika-lv added the question Further information is requested label Sep 23, 2020
@kelvin-lu
Copy link
Contributor

kelvin-lu commented Sep 23, 2020

Hi @aoshika-lv, I believe you are correct on all accounts - if the device Id is not available in the params via amp_device_id, we should fall back to the other options / a base64Id. Feel free to create a PR and assign a maintainer to review, or we can get to it in the following days/week.

Thanks for flagging this!

@aoshika-lv
Copy link
Contributor Author

Hi @kelvin-lu. Thank you for your quick reply!
Okey. I will create the PR as soon as possible.

aoshika-lv added a commit to Locationvalue/Amplitude-JavaScript that referenced this issue Sep 24, 2020
aoshika-lv added a commit to Locationvalue/Amplitude-JavaScript that referenced this issue Sep 24, 2020
aoshika-lv added a commit to Locationvalue/Amplitude-JavaScript that referenced this issue Sep 25, 2020
jooohhn pushed a commit that referenced this issue Sep 25, 2020
* Make it fall back to other options/a base64Id, if the device Id is not available in the params via amp_device_id. #302
github-actions bot pushed a commit that referenced this issue Sep 25, 2020
## [7.2.2](v7.2.1...v7.2.2) (2020-09-25)

### Bug Fixes

* Unavailable deviceId fallbacks ([#303](#303)) ([e0d39fd](e0d39fd)), closes [#302](#302)
@github-actions
Copy link

🎉 This issue has been resolved in version 7.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
2 participants