I am using this code to call a javascript function and then redirect PHP page.
<script type='text/javascript'>
mixpanel.track('login: Login ', {'page name' : document.title, 'url' : window.location.pathname});
</script>;
<?php
header("Location:".$domain_name."/services.htm");
?>
But this code is not working, if i don’t redirect then js function works fine.
i also tried ob_start(); and ob_end_flush(); but nothing worked. How can use JS function before redirect. i am new to JavaScript and PHP header function.
PHP runs on the server and JavaScript runs in the browser. You can’t just mix them together like that.
What you need to do is do the redirect with JavaScript, and not PHP.
UPDATE: The redirect is triggering before
mixpanel.trackis complete. You need to pass a function to the callback docs, so it runs once it’s done.