Skip to content

Instantly share code, notes, and snippets.

@vudngo
Created January 3, 2017 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vudngo/e129e8e18e1343c774ab6609181b6695 to your computer and use it in GitHub Desktop.
Save vudngo/e129e8e18e1343c774ab6609181b6695 to your computer and use it in GitHub Desktop.
<!-- Begin Call Tracking Code -->
<!-- Omit http from path to ensure protocol is same as current request -->
<script src="//cdn.invoca.solutions/optimizely/optimizely-1.0.js"></script>
<script src="//solutions.invocacdn.com/js/pnapi_integration-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">
//Grab Google Analytics Visitor ID
function getClientId() {
// If ga is defined, check for the clientId and return it
if (typeof ga !== 'undefined' && typeof ga.getAll === 'function') {
var clientId = ga.getAll()[0].get('clientId');
return clientId;
// otherwise, return false so waitFor knows to try again within the time threshold
} else {
return false;
}
}
function callInvoca(clientId) {
var invocaParams = {
pid: Invoca.Tools.readInvocaData("pid", Invoca.Tools.readUrl("pid")) || "default_id",
g_cid: clientId,
goal_url: Invoca.Tools.readInvocaData("goal_url", getVariationsInParameters() && generateConversionUrl("invoca_phone_call")) //replace invoca_phone_call with goal_url name used
}
Invoca.PNAPI.integration({
networkId: 1078,
numberSelector: ".invocaNumber", //carried over from existing code
defaultCampaignId: "int_trv_camp",
poolParams: invocaParams
});
}
//Attempts to gather GA Visitor ID for 1000ms before running Invoca Function
Invoca.Tools.waitFor(getClientId, callInvoca, 'noCid', 1000);
</script>
<!-- End Call Tracking Code -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment