/** * Get a PageView analytics object * @return Analytics object */ public function pageViewAnalytics($url = "", $title = "") { $result = null; $analytics = $this->analytics(); if ($analytics) { if ($url == "") { $url = craft()->request->url; } /* -- We want to send just a path to GA for page views */ if (UrlHelper::isAbsoluteUrl($url)) { $urlParts = parse_url($url); if (isset($urlParts['path'])) { $url = $urlParts['path']; } else { $url = "/"; } if (isset($urlParts['query'])) { $url = $url . "?" . $urlParts['query']; } } /* -- We don't want to send protocol-relative URLs either */ if (UrlHelper::isProtocolRelativeUrl($url)) { $url = substr($url, 1); } /* -- Strip the query string if that's the global config setting */ $settings = craft()->plugins->getPlugin('instantanalytics')->getSettings(); if (isset($settings) && isset($settings['stripQueryString']) && $settings['stripQueryString']) { $url = UrlHelper::stripQueryString($url); } /* -- Prepare the Analytics object, and send the pageview */ $analytics->setDocumentPath($url)->setDocumentTitle($title); $result = $analytics; InstantAnalyticsPlugin::log("Created sendPageView for `" . $url . "` - `" . $title . "`", LogLevel::Info, false); } return $result; }
public function getGlobals($forTemplate = "", $locale) { if ($this->renderedMetaVars) { return $this->renderedMetaVars; } if (!$locale) { $locale = craft()->language; } /* -- Load in our globals */ $meta = $this->getMeta($forTemplate); $siteMeta = $this->getSiteMeta($locale); $identity = $this->getIdentity($locale); $social = $this->getSocial($locale); $creator = $this->getCreator($locale); /* -- Get a full qualified URL for the current request */ $requestUrl = UrlHelper::stripQueryString(craft()->request->url); $meta['canonicalUrl'] = $this->getFullyQualifiedUrl($requestUrl); /* -- Merge the meta with the global meta */ $globalMeta['seoTitle'] = $siteMeta['siteSeoTitle']; $globalMeta['seoDescription'] = $siteMeta['siteSeoDescription']; $globalMeta['seoKeywords'] = $siteMeta['siteSeoKeywords']; $globalMeta['seoImage'] = $this->getFullyQualifiedUrl($siteMeta['siteSeoImage']); $globalMeta['seoImageId'] = $siteMeta['siteSeoImageId']; $globalMeta['seoTwitterImageId'] = $siteMeta['siteSeoTwitterImageId']; $globalMeta['seoFacebookImageId'] = $siteMeta['siteSeoFacebookImageId']; $globalMeta['seoImageTransform'] = $siteMeta['siteSeoImageTransform']; $globalMeta['seoFacebookImageTransform'] = $siteMeta['siteSeoFacebookImageTransform']; $globalMeta['seoTwitterImageTransform'] = $siteMeta['siteSeoTwitterImageTransform']; $globalMeta['twitterCardType'] = $siteMeta['siteTwitterCardType']; $globalMeta['openGraphType'] = $siteMeta['siteOpenGraphType']; $globalMeta['robots'] = $siteMeta['siteRobots']; $meta = array_merge($globalMeta, $meta); /* -- Merge with the entry meta, if any */ if ($this->entryMeta) { $meta = array_merge($meta, $this->entryMeta); } /* -- Merge with the global override config settings */ $globalMetaOverride = craft()->config->get("globalMetaOverride", "seomatic"); if (!empty($globalMetaOverride)) { $globalMetaOverride = array_filter($globalMetaOverride); $meta = array_merge($meta, $globalMetaOverride); } /* -- Add the helper vars */ $helper = array(); $this->addSocialHelpers($helper, $social, $identity); $this->addIdentityHelpers($helper, $identity); $this->addCreatorHelpers($helper, $creator); $this->setSocialForMeta($meta, $siteMeta, $social, $helper, $identity, $locale); /* -- Fill in the breadcrumbs */ $meta['breadcrumbs'] = $this->getDefaultBreadcrumbs($meta); /* -- Swap in our JSON-LD objects */ $identity = $this->getIdentityJSONLD($identity, $helper, $locale); $creator = $this->getCreatorJSONLD($creator, $helper, $locale); /* -- Handle the Main Entity of Page, if set */ $seomaticMainEntityOfPage = ""; $seomaticMainEntityOfPage = $this->getMainEntityOfPageJSONLD($meta, $identity, $locale, true); /* -- Special-case for Craft Commerce products */ if ($this->entryMeta && isset($this->entrySeoCommerceVariants) && !empty($this->entrySeoCommerceVariants)) { $seomaticMainEntityOfPage = $this->getProductJSONLD($meta, $identity, $locale, true); } /* -- Get rid of variables we don't want to expose */ unset($siteMeta['siteSeoImageId']); unset($siteMeta['siteSeoTwitterImageId']); unset($siteMeta['siteSeoFacebookImageId']); unset($siteMeta['siteTwitterCardType']); unset($siteMeta['siteOpenGraphType']); unset($siteMeta['siteRobotsTxt']); unset($siteMeta['siteSeoImageTransform']); unset($siteMeta['siteSeoFacebookImageTransform']); unset($siteMeta['siteSeoTwitterImageTransform']); unset($meta['seoMainEntityCategory']); unset($meta['seoMainEntityOfPage']); unset($meta['twitterCardType']); unset($meta['openGraphType']); unset($meta['seoImageId']); unset($meta['seoTwitterImageId']); unset($meta['seoFacebookImageId']); unset($meta['seoImageTransform']); unset($meta['seoFacebookImageTransform']); unset($meta['seoTwitterImageTransform']); /* -- Set some useful runtime variables, too */ $runtimeVars = array('seomaticTemplatePath' => ''); /* -- Return everything is an array of arrays */ $result = array('seomaticMeta' => $meta, 'seomaticHelper' => $helper, 'seomaticSiteMeta' => $siteMeta, 'seomaticSocial' => $social, 'seomaticIdentity' => $identity, 'seomaticCreator' => $creator); /* -- Fill in the main entity of the page */ if ($seomaticMainEntityOfPage) { $result['seomaticMainEntityOfPage'] = $seomaticMainEntityOfPage; } /* -- Return our global variables */ $result = array_merge($result, $runtimeVars); return $result; }
public function getGlobals($forTemplate = "", $locale) { if ($this->renderedMetaVars) { return $this->renderedMetaVars; } if (!$locale) { $locale = craft()->language; } /* -- Load in our globals */ $meta = $this->getMeta($forTemplate); $siteMeta = $this->getSiteMeta($locale); $identity = $this->getIdentity($locale); $social = $this->getSocial($locale); $creator = $this->getCreator($locale); /* -- Get a full qualified URL for the current request */ $requestUrl = UrlHelper::stripQueryString(craft()->request->url); $meta['canonicalUrl'] = $this->getFullyQualifiedUrl($requestUrl); /* -- Merge the meta with the global meta */ $globalMeta['seoTitle'] = $siteMeta['siteSeoTitle']; $globalMeta['seoDescription'] = $siteMeta['siteSeoDescription']; $globalMeta['seoKeywords'] = $siteMeta['siteSeoKeywords']; $globalMeta['seoImage'] = $this->getFullyQualifiedUrl($siteMeta['siteSeoImage']); $globalMeta['twitterCardType'] = $siteMeta['siteTwitterCardType']; $globalMeta['openGraphType'] = $siteMeta['siteOpenGraphType']; $globalMeta['robots'] = $siteMeta['siteRobots']; $meta = array_merge($globalMeta, $meta); /* -- Merge with the entry meta, if any */ if ($this->entryMeta) { $meta = array_merge($meta, $this->entryMeta); } /* -- Add the helper vars */ $helper = array(); $this->addSocialHelpers($helper, $social, $identity); $this->addIdentityHelpers($helper, $identity); $this->addCreatorHelpers($helper, $creator); $this->setSocialForMeta($meta, $siteMeta, $social, $helper, $identity, $locale); /* -- Get rid of variables we don't want to expose */ unset($siteMeta['siteSeoImageId']); unset($siteMeta['siteTwitterCardType']); unset($siteMeta['siteOpenGraphType']); unset($siteMeta['siteRobotsTxt']); unset($meta['twitterCardType']); unset($meta['openGraphType']); /* -- Set some useful runtime variables, too */ $runtimeVars = array('seomaticTemplatePath' => ''); /* -- Return everything is an array of arrays */ $result = array('seomaticMeta' => $meta, 'seomaticHelper' => $helper, 'seomaticSiteMeta' => $siteMeta, 'seomaticSocial' => $social, 'seomaticIdentity' => $identity, 'seomaticCreator' => $creator); /* -- Swap in our JSON-LD objects */ $result['seomaticIdentity'] = $this->getIdentityJSONLD($result['seomaticIdentity'], $helper, $locale); $result['seomaticCreator'] = $this->getCreatorJSONLD($result['seomaticCreator'], $helper, $locale); if ($this->entryMeta && isset($this->entrySeoCommerceVariants) && !empty($this->entrySeoCommerceVariants)) { $result['seomaticProduct'] = $this->getProductJSONLD($result, $locale); } /* -- Return our global variables */ $result = array_merge($result, $runtimeVars); return $result; }