I have a SinglePageApplication built with AngularJs. I want too add Facebook Custom Audience tracking pixel globally and update it manually every time user changes page (url).
Is it possible and if so, how?
Reference: https://developers.facebook.com/docs/reference/ads-api/custom-audience-website-faq/
I managed to resolve this by loading _fbq object:
and then calling 'PixelInitialized' event every time page changes.
Since then facebook correctly tracks my audiences.
Here's what I'm doing that seems to be working so far:
In my index.html file I removed the PageView function and commented out the pixel itself, as shown below.
Then, I configure my app as follows...
Now, for each state change, I use the onEnter and onExit to fire off the "events" I want to capture:
I'm guessing that, if I wanted to, I could simply move any
fbq('track', "PageView");
code into a controller. For my use case, though, tracking from state changes works perfectly for monitoring flow from within my app.Hope this helps someone else.
Into Single Page Application(SPA) you must disabled automatic listen on push State, pop State and windows history as Facebook pixel library by default hook into windows.history and push/pop state.
according to @lari answer about another related question to your question and Josh's Post blog