mixpanel analytic in wordpress blog not working - php

I am trying to use mixpanel for analytic in my Wordpress blog (just for learning).
My blog is all php.
I got the code from mixpanel's website and put it in my header.php file.
<!-- start Mixpanel --><script type="text/javascript">(function(c,a){window.mixpanel=a;var b,d,h,e;b=c.createElement("script");b.type="text/javascript";b.async=!0;b.src=("https:"===c.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.0.min.js';d=c.getElementsByTagName("script")[0];d.parentNode.insertBefore(b,d);a._i=[];a.init=function(b,c,f){function d(a,b){var c=b.split(".");2==c.length&&(a=a[c[0]],b=c[1]);a[b]=function(){a.push([b].concat(Array.prototype.slice.call(arguments,0)))}}var g=a;"undefined"!==
typeof f?g=a[f]=[]:f="mixpanel";g.people=g.people||[];h="disable track track_pageview track_links track_forms register register_once unregister identify name_tag set_config people.set people.increment".split(" ");for(e=0;e<h.length;e++)d(g,h[e]);a._i.push([b,c,f])};a.__SV=1.1})(document,window.mixpanel||[]);
mixpanel.init("MYKEY");</script><!-- end Mixpanel -->
Here, MYKEY is my actual key.
Now, I want to see page views for each of my blog posts.
I am putting following code in page.php, which gets called each time a post is viewed (afaik).
<script type="php">
mixpanel.track("Viewed Post")
</script>
But I am not getting any data back. Can someone please help me here?

I am using Mixpanel on my blog (along Google Analytics). Some suggestions
Make sure you've put the mixpanel code before the head closing statement </head>. In many themes you will find a lot of code below the </head> for example the <body class="<?php hybrid_body_class(); ?>"> in the case of hybrid based themes
I am not sure why you are using <script type="php"> the usual is <script type="text/javascript">
Hope this helps!

in all my wordpress website i want to delete this mixpanel, someone can tell me how i can do that?

MixPanel does not work well with Wordpress blog. I would use Google Analytics.

Related

How to properly include php files inside wordpress plugin

Hi I am creating my first custom wordpress plugin.
I have run into an issue when I try to create a link in an included file to one of the plugin menus in the dashboard.
Here is my code for the link
<p>Add a new record</p>
>
As you may have noticed it is using a full URI.
I have tried using ?page=add-members as the href source and it seems to work.
I am wondering if that is the appropirate method to do this or if there is a more standardized way.
Thanks in advance.
I believe what you are looking for is the get_site_url function.
<?php echo get_site_url(); ?>
So ideally you would link it like:
<p>Add a new record</p>
You can read about it on the docs.

Add html div tag based on file name

Sorry if this is a nooby question, but I have the following problem:
I have some sort of a Documentation as a multiple webpages. I created a basic navigation bar on the left of the screen using a tutorial... To be able to mark the active link every page has its own unique navigation adding it's own link to a specific div class.
The problem is that if I wanted to add another page to my collection I would have to add the link in every html document.
I know that there is a possibility to include other pages Php code to have one navigation document, but I have no idea on how to achieve that the current page is getting highlighted.
I would appreciate any help.
If you want to have your navigation on a separate file it is completely possible and is actually preferred.
Use any of the following:
require
include
require_once
include_once
So let's say your navigation HTML is located at nav.php you would do something like:
<html>
<head><title>My Awesome Website</title></head>
<body>
<div id="nav-wrapper">
<?php
include_once("nav.php");
?>
</div>
<div id="contents">
<h1>Hello World!</h1>
</div>
</body>
</html>
If you update your navigation in the future you will only need to update one file (nav.php).
So if you want to make a new function please read this:
http://php.net/manual/en/functions.user-defined.php
There is full info how to create function.
Pass to function what page is active you can just simply in this way:
function menu($active)
{
echo $active;
}
menu($active);
It's hard to say more, because you didn't show us anything, a construction of HTML or PHP. Please read linked above tutorial. I think it will be enough in this stage of PHP learn.
Because of Grzegor J I found this Stackoverflow question which pretty much solves my problem.
Thanks to everyone for trying.

Twitter button not showing URL to Tweet

I'm trying to implement a 'Tweet' button on my wordpress site and am having an issue where the URL doesn't show in the tweet.
It shows the hashtag and the account but not the URL.
My code is as follows:
Tweet
If i don't use the data-url then it just inserts the base domain name and not the full URL.
Any ideas?
Have you tried the code on the twitter page instead? Have a look at the twitter API here.
You are missing javascript code.
You probably got your code from HERE
For sharing a link, the javascript code is
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
Just add this code after your anchor tag.
I had the following code:
Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
But that didn't work, so I tried a simplified version:
Tweet<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
And this one worked just fine. Just keep in mind that the username has to be somehow integrated in your theme settings, if it's not, you can change:
<?php echo of_get_option( 'ac_twitter_username' ); ?>
For your twitter username.
I hope this works, It took me a while to find this more generic approach. I don't fully know what I'm doing, so if anyone sees an issue with this approach, please let me know. So far, it works great.
Thanks!

Adding PHP to a static site. Not sure if my workflow is right

Let's try to explain the title of my question to be the more concise I can: I'm basically designing a static HTML website from scratch. Nothing to worry about here.
The point is that I'm trying to include some links that will retrieve some items (a product inventory) from a database (and therefore the site won't be so 'static' anymore), as there're > 300 products and creating an html for each one is not feasible.
After googling and reading several sites for days, the "easiest" solution I came up with is to use PHP and MySQL. Again, nothing to worry about. Just took my time for reading documentation and move along.
My question is more related about the correct workflow for integrating both worlds. Let's see my idea in code:
This is one schematic example of the page where you can browse some products (e.g: product.html):
<html>
<head>
<title>My Site - These are our products</title>
</head>
<body>
<!--Site goes here-->
Search by name
Search by color
<!--rest of site goes here-->
</body>
</html>
Where the links
product_search_by_name.php
product_search_by_color.php
are actually a modified clone of the same page (product.html). This is, keeping same html code, plus the .php code embedded into it, as I want to have the DB results displayed into a div on that same page, keeping exactly same layout.
So, am I doing this right if I want to maintain the appearance of the whole website? I'm absolutely wrong from the base and should start again? Should I give up and work selling frappuchinos on a Star*ucks?
As a sample of the idea I want to achieve is the following: http://www.w3schools.com/tags/default.asp (when you click on the left menu bar, the center zone updates with the content). By the way, are they using AJAX on that website to update just the center zone, or I'm misunderstanding what is AJAX for?
I'm sure I'm missing something but I'm too confused to separate the sheep from the goats, so I'd thank a lot any tips you can give to me (and additional documentation on the internets to read as well).
There are two main ways to merge or migrate from static HTML to dynamic HTML (PHP, PERL, whatever).
(1) One is to have most of the contest as HTML, and the stuff like inventory as dynamic.
<html>
<head>
<title>My Site - These are our products</title>
</head>
<body>
<h1>My Site - These are our products</h1>
<?php
// php code to retrieve links
?>
</body>
</html>
(2) To have a full PHP site.
<?php
echo "<html>" . "\n";
echo "<head>";
echo "My Site - These are our products"
echo "</head>";
echo "<body>" . "\n";
// php code to retrieve links
echo "</body>" . "\n";
echo "</html>" . "\n";
?>
Many developers start by merging both HTML & PHP.
I suggest to learn how to do a very simple but full php site, connect to a database, retrieve some records with a S.Q.L. query, display them as read-only text or links, and later you may change to the other HTML plus PHP way of doing things.
There are several editors and tools to help develop in PHP, specially by looking for a PHP function, or just highlight HTML tags. Scintilla (Linux) or Notepad++ in windowze, its a very simple yet useful tool.
Cheers.
Well, if you want it to make it using Ajax ...
You might want to do the following.
Create the two files as you said, those are not to be included in the HTML file.
Create a JavaScript function to call the files, You can use jQuery api, to link to php. http://api.jquery.com/jQuery.post/ or http://api.jquery.com/jQuery.get/
Link the click of the button inquired to call the JavaScript function, and add html you get from php to the tag you want.
You can create a index.php page and put down your html code in it. It looks like this
<html>
<body>
<!--- links goes here -->
Search Products
</body>
</html>
If you are retrieving products from a database and if you want to create multiple links for the products create a function in your function.php which pulls all the product name from the database. Now add this function into your index.php
index.php
<?php include ('functions.php')?>
<html>
<body>
<h3>Product List</h3>
product name
</body>
</html>
Always embed html in php file. Do not embed php in html file. File should have .php extension.

Passing a complex PHP variable to be written by an external .js file

Hello all!
This is my first post on stackoverflow. After hours of searching and trialing, StackOverflow coming up on alot of possible fixes: I decided it was time to ask the question myself.
I am constructing a Wordpress powered portfolio website for my own web design work. I have done some extensive customization thus far and I am now at the final stretch. Also note I do not expect direct plugin support but I will cite the plugins being used, that it could help potentially.
Preface:
I am using a plugin called NextGen Gallery, this plugin powers my portfolio. All my clients have their own gallery which I display on the portfolio site.
I have also installed a plugin called Fancybox for Wordpress. This plugin allows for a good looking lightbox display of all my clients.
I have a third plugin called Custom Fields for NextGen Gallery, this plugin allows me to add custom fields specific to each gallery and image within. You will see I have already utilized this by creating custom thumbnails through a link added through the Custom Fields plugin.
All that being said my goal was to, utilizing the custom fields plugin, add html rich description text and html rich Client title text specific to each slide. The top of the slide reads the Client name and under the slide reads a description with links. I have made some progress but here is where I am stuck...
Problem:
jquery.fancybox.js will not take my PHP variable generated by "NextGen Custom Fields" plugin as it is written in a file called gallery-popportfolio.php (The template file for NGG). I have tested this extensively and had the same results. A few simple code bits added:
Within gallery-popportfolio.php I place this:
<?php $clientname = nggcf_get_gallery_field($gallery->ID, "clientnamelink"); ?>
<script type="text/javascript"> var clientname = '<?= $clientname ?>'; </script>
<script type="text/javascript" src=".../jquery.fancybox.js"></script>
Within jquery.fancybox.js I insert this:
(This is a excerpt, the only thing I add is .append(clientname):
append('<div class="fancybox-bg" id="fancybox-bg-n">').append(clientname)
Now what makes this quite interesting to me, is that within gallery-popportfolio.php if I asign $clientname to be something static like a line of text. The .js file will than accept the variable and place it exactly where I need it to be. The problem is when I apply this dynamic string to the $clientname variable it simply renders nothing. As well as this, when I echo $clientname with the complex variable in the PHP file I am getting a correct result.
Question:
I am stumped, I seemed so close yet no proper result.
Am I missing a step to make the external .js file accept a more complex php variable?
Is it possible I simply need to move the php code I have written elsewhere?
What is my next best step?
NOTES:
I was following this thread to reach where I am now: StackOverflow Thread
My working portfolio site is at: EoghanMcInerney.com
Thanks in advance for any help! Much appreciated!
If you mean "not a string" by complex variable, for $clientname, then your code won't work.
In this line of code :
<script type="text/javascript"> var clientname = '<?= $clientname ?>'; </script>
$clientname should be a string without the ' character. I suggest you change the code above to
<script type="text/javascript"> var clientname = <?= json_encode($clientname) ?>; </script>
And when you append you should construct a string from clientname and append that.

Categories