Welcome to the forums. And congratulations on using a myDAQ with the DAQmx API instead of DAQ Assistant, or some other myDAQ express VI.
What you need to do is as you suggested, create a common clock that is shared between both tasks. So you would make an analog task, and for the timing source provide an internal clock channel. Depending on your hardware there are several and some are more flexible then others. You then make a digital reading task that uses the same clock source, then you start your analog and digital task. Neither one will take samples until the clock source you created has started, but when it does it will take samples from both, at the same time. So the third task you need to start, is the one associated with the common clock source.
Another method that I just found by searching I've never tried but looks like it creates the analog task, then uses that clock from that task to read from the digital task. It can be found here.
https://decibel.ni.com/content/docs/DOC-12185
Also notice in that example how they only create the tasks once, and close once. This is a better way of programming because there is overhead from opening and closing the task over and over. Also you are doing finite reads so your data won't be continuous, it will have breaks between loop iterations and data will be lost where the example I linked to will continue reading where the last read left off.
EDIT: For any of this to work your hardware needs to support providing the internal clock to both tasks. I think myDAQ should be able to do this but I have never done this with that hardware.