I'll answer for smooth closed manifolds. I'll also assume choose Riemannian metrics everywhere. (The space of such metrics is convex and therefore contractible, so anything depending on the metric will usually be canonical up to homotopy.) Suppose we have a smooth embedding $f:N\to M$ of codimension $d$. This gives a $d$-dimensional vector bundle $\nu_f$ over $N$, whose fibre at $x$ is the orthogonal complement to $f_*(T_xN)$ in $T_{f(x)}M$. Next, for $(x,v)\in E(\nu_f)$ I define $g_1(x,v)$ to be $\alpha(1)$, where $\alpha:\mathbb{R}\to M$ is the geodesic with $\alpha(0)=f(x)$ and $\dot{\alpha}(0)=v$. This map $g_1:E(\nu_f)\to M$ will be an embedding on some neighbourhood of the zero section. Choose a smooth embedding $h:E(\nu_f)\to E(\nu_f)$ whose image is close to the zero section, and which is the identity on some even smaller neighbourhood of the zero section. Now put $g=g_1\circ h:E(\nu_f)\to M$; this is called a tubular neighbourhood of $f$. We can define a map $f^!:M_\infty\to E(\nu_f)_\infty$ of one-point compactifications by $f^!(g(x,v))=(x,v)$ and $f^!(m)=\infty$ whenever $m$ is not in the image of $g$. This is called the Pontrjagin-Thom construction. This in turn gives a map $\widetilde{H}^*(E(\nu_f)_\infty)\to\widetilde{H}^*(M_\infty)$. Now $M$ is compact, so the point $\infty\in M_\infty$ is isolated, so $\widetilde{H}^*(M_\infty)=H^*(M)$. On the other hand, $E(\nu_f)_\infty$ is otherwise known as the Thom space $N^{\nu_f}$, so (provided that $\nu_f$ is oriented) there is a canonical element $u\in \widetilde{H}^d(N^{\nu_f})$ (called the Thom class) such that $\widetilde{H}^d(N^{\nu_f})$ is freely generated by $u$ as a module over $H^*(N)$. We now have an element $v=(f^!)^*(u)\in H^d(M)$; this is called the cohomology class of $N$ (or of $f$) in $M$.
The cohomology class of the diagonal is obtained by applying this procedure to the diagonal embedding $f:M\to M^2$ defined by $f(m)=(m,m)$.